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

combo box linking 1

Status
Not open for further replies.

Alexengland1

IS-IT--Management
Mar 18, 2004
88
US
I'm trying to link combo boxes together on a form. In otherwords if you select option "1" in combobox1 then "selection list 1" would pop up in combobox2. Is there a quick and easy way to do this, say with the form wizard, or will I have to do an IF statement? Any help would be appreciated.

Thanks,
Alex
 
Hi Alex.

What you need to do is to set up the RowSOurce of the dependent combo like so in the init() of the form. I tell you to use the form's Init() because this is the only place that you can be certain that both combos have been instantiated. Code similar to this in the form's init:

Code:
lcRowSource = 'SELECT Yada, Nada, Blah FROM SomeTable '
lcRowSource = lcRowSource + 'WHERE SomeField = ( Thisform.BossCombo.Value ) INTO CURSOR csrDetails '
lcRowSource = lcRowSource + 'ORDER BY Blah'
*** Now set up the list box's properties
WITH Thisform.cboDependent
  .RowSourceType = 3
  .RowSource = lcRowSource
  *** Don't forget to repopulate the control's internal list
  .Requery()
  *** Initialize it to display the first item
  .ListIndex = 1
ENDWITH

Marcia G. Akins
 
Alex;

I really liked Marcia's coding example, and I'll try it when I log off.

My somewhat crude way of doing this was to run a query in the valid snippet of the main combobox (based on this.value) that would populate the list of the dependant combobox.

I create a cursor 1st in the init, and then append the query to the cursor. I use a modified version of the autofill combobox that mgannon kindly posted in the faqs section. Works quiet well for me.

HTH
 
Hi Alex.

>> I'm trying to link combo boxes together on a form <<

I almost forgot one important piece of information here:

You need this line of coe in the Boss Combo's Valid:

Code:
Thisform.DependentCombo.Requery()






Marcia G. Akins
 
Thanks Marcia for your assistance, I will give that a shot and see if I can get it to work. Thanks!!
 
I have so far been unsucceful with the SQL statement. WSMYTH what exactly was your method again?
 
How about posting what isn't working? If it's an SQL statement, make to include the relavant table field definitions.

Rick
 
This is what I have done so far.
Code:
lcRowSource = 'SELECT cb1value,cb2value,cbdesc from scantype'
lcRowSource = lcRowSource + 'WHERE cb2value = ( Thisform.combo1.Value ) .and. !empty(cb2value) INTO CURSOR csrDetails '
lcRowSource = lcRowSource + 'ORDER BY cb2value'
In Valid for combo1 I put
Code:
Thisform.combo2.Requery()
I get nothing in combo2 and an "Unrecognized command verb" on the Requery() statement under combo1.

I've got combo2 properties set to:

Control Source= Tiftest.doc_type2 (Tiftest is the final output database)
RowSource= lcrowsource
RowSourceType= 3

Since I am somewhat unfamiliar with SQL statements in VFP, I am unsure of where to go from here. Any help would be greatly appreciated, seeing as I will be needing this on multiple forms.
 
i think it's a typo. the code
Code:
lcRowSource = 'SELECT cb1value,cb2value,cbdesc from scantype'
should read
Code:
lcRowSource = 'SELECT cb1value,cb2value,cbdesc from scantype '
notice the space after scantype.

sure hope this helps. peace! [peace]

kilroy [trooper]
philippines

"Illegitimis non carborundum!"
 
Alex;

I still think Marcia has the better solution. Try it a few more times. If you're still stuck please let me know and I'll post my kluge code tomorrow nite if you are unsucessful.

wsmyth
 
i also noticed: ORDER BY should come before INTO CURSOR phrase. so your sql statement should look like this:
Code:
lcRowSource = "SELECT cb1value,cb2value,cbdesc FROM scantype WHERE cb2value = Thisform.combo1.Value AND NOT EMPTY(cb2value) ORDER BY cb2value INTO CURSOR csrDetails"
i hope this helps. peace! [peace]

kilroy [trooper]
philippines

"Illegitimis non carborundum!"
 
Hi Alex.

Sorry I took so long to respond, but I see that you have been in very good hands ;-)

The others were correct about the typo in your code - you needed the space at the end of the line to avoid the "Unrecognized command verb" error.

Also, TorturedMind is incorrect when he says that the ORDER BY clause muct come before the INTO CURSOR clause. It wouks just fine the other way around.

Also, you do not need to specify the RowSOurce as lcRowSOurce in the property sheet. You do, however, have to set it in code in the Init() after you construct it.

HTH.



Marcia G. Akins
 
Still Getting "Unrecognized command verb" on the requery() statement and combo2 is still blank.

Changed code to this:

Code:
lcRowSource = ' SELECT cb1value,cb2value,cbdesc from scantype '
lcRowSource = lcRowSource + 'WHERE cb2value = ( Thisform.combo1.Value ) .and. !empty(cb2value) ORDER BY cb2value INTO CURSOR csrDetails'

Any other thoughts? I'm basically flying blind here. Thanks
 
Okay I've gotten past the "Unrecognized Command verb" error by removing the rowsource settings from the combo2 properties window and coding them in with the form init code. However combo2 is still empty, there is nothing there, no matter what I select in combo1.

Any thoughts?
 
Thank you everyone for your help, I was finally able to figure out the errors I made, and now its working like a champ. Its crazy how one little character in the wrong place can cause a world of problems.

Ahhhh the life of a programmer.

Thanks again everyone!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top