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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is it when i chose an item in a combobox using cursor it edit the first record in my table? 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
585
PH
Hi everyone, its been days i trying to figure out this....
I have a form (used wizard in creation) i added a search combobox that is initialised using CsrName (cursor) to list names and idnumber.

But everytime i choose one name, it automatically edits the first record of my table to the name i chose? so everytme i click again the combobox, i already have two names in the cursor.... how is that happening? Thanks everyone...
 
It sounds like you might have the combo's ControlSource pointing to the same cursor that you use to populate the combo.

But it's hard to be sure without some more information. In particular, what are the values of the following properties: RowSource, RowSourceType, Style, ColumnCount, BoundColumn, BoundTo and ControlSource? And what is the data type of the field that the ControlSource points to?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You are right Mike!!!! You are so great… thanks so much…,
 
Good to hear that it is working now, Mandy. Thanks for letting me know.

If you would like a little background info ...

In general, when you move the highlight in a combo box, the effect is to update the current record in the ControlSource cursor. This is not so very different from typing into a text box, or toggling a checkbox. In all these cases, you are changing the value of the control. And changing the value of a control that has a ControlSource has the effect of updating the field to which the ControlSource is pointing.

So that is exactly what you are seeing. It happens that, in your case, the ControlSource's cursor is also the cursor you used to populate the combo. So, if the combo is populated from the Customer cursor, and that cursor is sitting on Customer A, as you move the highlight, that record will be updated with the value for Customer B, Customer C, and so on, in turn.

This is less of a problem if the combo's RowSourceType is 2 (Alias) or 6 (Fields). In those two cases, moving the highlight within the combo has the effect of moving the record pointer within the cursor. So the result is the same as in other cases, but you are in effect updating the ControlSource field with itself. Although (in most cases) that will do no harm, it is something that should be avoided.

The bottom line is never to use the same cursor for the ControlSource as you are using for the RowSource. (And, of course, when I use the word "cursor" here, it also applies to physical tables or views.)

I hope this makes sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
thank you so much Mike... I always learn something new from you... thank you for always giving me explanations so that the next I'll use it, i will know how and when to use it... My project is actually finished and its working but from time to time, everytime i use my app, there will always be that "i still need to add this..." feeling... its as if it never stops that i have to update my app... Thanks again Mike...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top