Helpful Information
 
 
Category: Visual Basic Programming
Access Programming Question

Howdy y'all,

A friend of mine enlisted my help for programming a database she's using for her senior project. One little problem, though: it's an Access DB and I don't know VB, nor do I have the time to learn the ins and outs. I would appreciate a little code snippet/example of how to do the following:

I have two combobox controls on a form: Combo1 and Combo2.

Combo1 contains category information (e.g., Home, Garden, Tools, ...)
Combo2 contains item information based on what is selected in Combo1.

My question: How do you code the OnChange event for Combo1 to grab the selected value in Combo1, construct a SQL query to grab the necessary items, and then populate Combo2 with the new items?

Thanks for any help,

Well, I haven't worked with VB in ages, and I'm not certain what method you're using to access the DB (I'm assuming ADODB in my example), but I hope this helps:


Dim sText As String
Dim sSQL As String
Dim rs as ADODB.Recordset
sText = Combo1.Text

sSQL = "SELECT foo FROM bar WHERE baz = " & sText

' Run your SQL statement here
Combo2.Clear
rs.Open sSQL
While not rs.EOF
Combo2.AddItem (rs("FieldName"))
rs.MoveNext
Wend
rs.Close

Thanks Scorpion.










privacy (GDPR)