Getting value in a combobox based another combo.

Posted on 2006-04-26
Last Modified: 2011-09-20
How can I populate the combo2 from the value in combo1 both of these values are obtained from database. The following code is suppsed to do it however the program doesnt read this code when I change the selection in combo1

Private Sub CmbState_Change()   <---Is this the right function name?
Dim conn
Dim rec
Dim myvalue

myvalue = Me.CmbState.Text

Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.mdb;Persist Security Info=False"
esql = "select BAT from Dataset where STATE = " & myvalue & ";"
rec.Open (esql), conn, adOpenStatic, adLockReadOnly
If rec.RecordCount > 0 Then
    Do Until rec.EOF
        FacilitySelection.CmbBat.AddItem rec("STATE")
End If
Set conn = Nothing

End Sub
Question by:Aiysha
    1 Comment
    LVL 4

    Accepted Solution

    that's not the right event.  change occurs when you type in the text portion

    i would put it in the click event which occurs when you click in the list

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now