Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combo box/SQL source
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00101802
Message ID:
00102186
Views:
27
>>I want to populate a combo with results from an SQL expression and at the same time set its initial value to match a particular "row" from the SQL result.
>>
>>eg. I do "SELECT ColDesc, ColCode FROM Colours ORDER BY 1 INTO CURSOR C_Col " as the rowsource for the combo and gives a result of...
>>Black B
>>Green G
>>Red R
>>and I want to display "Red" as the default.
>>
>>I don't know in advance that red is the 3rd row, so a can't simply set combo.value to 3. Worse than that the cursor C_Col doesn't exist for some strange reason during the form.init, so I can't do anything there either.
>>
>>I would've thought that since the combo inits before the form init that C_Col should exist already ???
>>
>>What's the best way?
>
>David, is your SELECT code in the combo RowSource? Is your RowSourceType = 3 (SQL)? If not, then where is the SELECT code run? If the SELECT is in the RowSource this should run OK and allow you to set the correct value in the form INIT. Use the debugger to follow the code and see where the C_Col cursor is loaded.
>
>Remember that a cursor has a 'real' name of 01234567.tmp (or similar) and resides in your TEMP directory. Depending on what you want to do with it you may have to use dbf() to get the correct name. Certain commands require the real name, not the alias.
>
>To set the correct value on the combo, in the form INIT code try adding
>
>thisform.mycombo.value = "R"
>
>to set the combo to the correct line. I'm assuming that the value is the code, and displayvalue is the actual color.
>
>HTH
>Barbara

Thank you both (Barbara and Kamal). Yep, I agree that something must be wrong. I do a
IF USED("C_Col")
WAIT WINDOW "It's here!"
ENDIF
in both the init of the combo and the form and don't see the message. Strange.
Anyway, you've convinced me that it should work! So leave it with me and I try your suggestion
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform