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

Two combo box in the same forms.

Status
Not open for further replies.

indraT

IS-IT--Management
Jan 18, 2004
24
CA
Hi there,

I have a form in which there is one combo box.when user select any items from that combo box on the basis of that i want another combo box to display the information. this is in the same form. Is there any information how can i do this.

the first combo box display all the items group.

the second combo box have all the item but it should only display those items in the group selected in first combo box.

any inf. please.
Thanks.
Indra.
 
Indra

You have the ability to change the record source of a combo box programatically.

After the end user selects an item from the first combo box, the code would then change the record source of the second combo box, presumably apply an applicable WHERE clause, and requery the second combo box to load the new list.

Here is some sample code to give you an idea...
Code:
Private Sub CompanyCodeCmBx_AfterUpdate()

Dim strSQL As String, strWhere As String, strQ As String
Dim strID As String
Dim lngID As Long

strQ = Chr$(34)

strSQL = "SELECT M.ModelID, M.CompanyCode, M.ModelName FROM ModelTbl as M"

If Len(Nz(Me.CompanyCodeCmBx)) > 0 Then
    strID = Me.CompanyCodeCmBx
    strWhere = " WHERE M.CompanyCode = " & strQ & strID & strQ
    Me.ModelCmBx.RowSource = strSQL & strWhere
    Me.ModelCmBx.Requery
End If

End Sub

Here, the model names in the second combo box are restricted to whatever the end user selects for the company code from the first combo box.

Since this example uses a string or character field, the ID value has to be enclosed within quotes.

If the ID field is numeric, code would be ...
Code:
If Nz(Me.CompanyCodeCmBx) > 0 Then
    lngID = Me.CompanyCodeCmBx
    strWhere = " WHERE M.CompanyCode = " & lngID
    Me.ModelCmBx.RowSource = strSQL & strWhere
    Me.ModelCmBx.Requery
End If

Hope this helps.
Richard
 
Thanks Richard,

I am checking this and let you know once done.

Indra.
 
Hi there, i am having problem with combox related update, please help me.

in my form i have a combo box whose record source is table/query. i also have other field inthe form. what i wantis when user select item number form the combo box the ohter field in the forms like item description, unit and price will automatically fillup, according to the itemnumber selected. is there any way i can solve this problem in adp, its working fine in mdb.

thanks.
Indra.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top