Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to use text boxes

Status
Not open for further replies.

breezett93

Technical User
Jun 24, 2015
128
US
Hello,

I have created a simple data entry form with labels, text boxes, and an add button. When I test run the form, I am unable to access the text boxes no matter what code I use.

I have some experience with Visual Basic which is how I got this far, but I am not understanding why I can't enter any data into the text boxes.


Thanks.
 
Can you be a bit more explicit. When you say you are unable to access the text boxes, do you mean that you can't click in them, or type in them? In other words, are they greyed out?

If that's the case, check the text boxes' Enabled property (which should be .T.) and their ReadOnly property (which should be .F.).

Do the text boxes have anything in their ControlSource property? If not, that's OK. But if they do, check that the table (the one referenced in the Control Source) is not at end of file, or is not empty.

If that doesn't answer your question, perhaps you can explain a little more clearly what the problem is.

By the way, welcome to the forum.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I cannot click in them nor type in them; however, I do have all of them enabled and disabled ReadOnly. They are not greyed out.

Each text box does point to a database column through ControlSource, and the add button would create a new record.

The database is empty so that contacts can be entered. How would I check if it's "not at end of file"

Thanks.
 
The fact that the "database" (I assume you mean the table) is empty would explain what you are seeing. When a text box has a control source, it is expecting the user to edit the data that the control source is pointing to. If that data doesn't exist, then there is nothing to edit, so the box is disabled.

What you need to do is to put some code in the Click event of your button. The code should insert a new record in the table. The easiest way to do that is with [tt]APPEND BLANK[/tt]. The code should then refresh the form ([tt]thisform.refresh[/tt]).

Once you have done that, the text boxes should be enabled. You will then have to think about how you are going to navigate to other records, and to edit those other records. But let's take one step at a time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I was under the impression the ControlSource told the form where to send the data to, not where to get it from. That does make more sense now.

Yes, you are correct; the database is essentially one table with the typical contact information columns.

Thanks!

 
That's right. The ControlSource is a two-way street. It tells the text box (or other control) to get its data from the table. It also tells it to update the table with any data entered into the text box.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I'm noticing that a row is being skipped after each time I enter test data. Should the APPEND BLANK just be used one time and then removed from the button's click event, or should I remove the BLANK and add a different command for APPEND?
 
No. The purpose of the button is to add a new record to the table. Each time you click it, it should execute the APPEND BLANK.

Based on what you have told me, you should be seeing a new blank record each time you click the button. You then fill in the blanks. When you click the button again, that record will be saved and a new one generated.

If that is not what you are seeing, it is most likely because you have buffering enabled. If so, you will need further buttons, to commit (save your edits) and revert (cancel your edits). You will also need a way to navigate to the records you have already created. But, as you are just starting with this, you should take one step at a time. It's important that you understand what is happening, and what your code is doing.

It's also important, when you post a question here, that you state precisely and clearly what you are seeing. I'm sure you'll agree that just saying "a record is being skipped" doesn't tell us much.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Apologies for being vague.

This is exactly what I am seeing when I browse the table:

Row 0: testFirstName testLastName testCompany etc etc
Row 1:
Row 2: testFirstName2 testLastName2 testCompany2 etc etc
Row 3:

Essentially I have only clicked the add button twice. If you're suspecting buffering being enabled, where can I disable it?
I guess it could also be possible my primary key is not incrementing correctly.

Thanks
 
OK, that's a bit clearer. Based on what you have posted, it looks like buffering isn't the issue. So forget that for the moment. (In fact, buffering is quite important, and is something you will need to learn about in due course, but it's not relevant to this problem.)

That said, it's really impossible to diagnose this problem without knowing more about the form and the controls on it. One possibility is that you have some other code somewhere that appends a blank record (which never gets edited). But I can't know that for sure.

Let me ask you this. How did you go about creating this form? Did you use a wizard? Or did you start with a blank form, and then add the text boxes and the button? And, if the latter, did you set the properties manually, or did you use a builder? (In general, the best way to learn is to do everything manually, one step at a time. The wizards and builders have their place, but they won't help you to understand what is going on.)

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I created the form with a wizard based on the table I have. So it created all the labels and text boxes for me. It gave me this button bar, but I couldn't remove individual buttons; so I deleted the whole bar and added just one button. I also deleted the primary key label and text box because I want the system to auto increment. I added a ReadOnly text box to just display the current id.

I added SET CONFIRM ON because the auto-tab-to-next-box was driving me nuts.
I also set Formats for some of the text boxes; so I made some manual adjustments.

The code for the button is:
Code:
APPEND BLANK
Thisform.Text1.value = Thisform.Text1.value + 1
thisform.refresh
 
Given your aim is to learn Visual FoxPro, then I strongly recommend that you abandon the wizard, and build the form from scratch. Wizards give you a lot of code that is difficult to understand, and not easily accessible. So put to one side what you have done, and build a form manually, adding your functionality a little at a time - and, above all, being sure you understand what you are doing as you are doing it. That's really the only way to learn.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok, I have figured out why rows of records were being skipped left blank. After each data entry test, I have gone through and deleted everything in the Data Session area. Instead of returning the primary key to null, it was being set to 0 in each row. I thought nothing of it at the time. So when I would start up the form, it looked like I was successfully entering IDs 0, 1, 2, 3 etc; however, in the table it was entering 0 in the first row, then jumping past every following row with a 0 left behind.

I have now gone in and Removed Deleted Records which looks like my table has been successfully reset. However, this doesn't prevent the issue from happening again.

My question is two parts: 1)How can I set the primary key field to be unique; so that there is only one ID per record instead of having a bunch of records all with an ID of 0 or 1 etc, and 2)How can I tell the form to "remember" where it left off so that records aren't overwritten or a blank row is entered every time someone wishes to enter more data?

 
I created the form with a wizard based on the table I have

Mike has already said it, but I will add my 2 cents worth.
DO NOT use the WIZARDS if you want to learn Visual Foxpro.

The Wizards will generate an object (Form, Query, <whatever>) but it will create them using WHAT IT THINKS YOU WANT and quite often not what you really want.
Build these objects by hand and you will learn MUCH MORE about how things work.

Good Luck,
JRB-Bldr
 
Use the Integer (AutoIncrement) field for your primary keys and don't let the user see or touch them.

Tamar
 
I am using VFP 6. I believe that option is not available.
 
You could also have two rows each time you click the Add button, because you used the wizard and the add button already creates a new record on it's own. By adding APPEND BLANK you create a second one.

Bye, Olaf.
 
I did remove the original row of 8 buttons because I couldn't remove individual ones. So I recreated the add button from scratch.
 
because I couldn't remove individual ones

Again, since you used (and seem to be continuing to use) a Form created by a Wizard, you do not have the full control of the objects on it that the Wizard 'thinks' you wanted.

Get rid of the Wizard form entirely and build what you need on your own 'from scratch'.
Then you will be able to do what you need and want to do.

Good Luck,
JRB-Bldr
 
I hate to labour the point, but you have been strongly advised to get rid of the wizard, and to build your form from scratch. If you choose not to do that, you will continue to run into difficulties, and it will hinder your learning process.

In addition, you are not doing yourself any favours by using VFP 6.0. This is three versions out of date, and lacks many of the inmportant features of VFP 9.0, which is the current version.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top