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

Combo Box dependant on another-code is not working

Status
Not open for further replies.

larisa26

Technical User
Mar 12, 2004
2
0
0
US
I started pulling my hair out~. I am not experienced with coding and Access overall, but the project fell on my laps and I had to start learning it.
I’ve read the FAQs provided on this site thoroughly re combo boxes, but I can not make it work.
I have 2 combo boxes (AirportID and TerminalID) pulling out the information from the following tables:
AIRPORTS (table)
AirportID )PK
AirportCode
AirportName

TERMINALS(table)
TerminalID )PK
TerminalName
AirportID )FK

I want to be able to select an airport name in the first combo box (AirportID) which then causes a second combo box (TerminalID) to bring out the Terminals for that specific airport.

In the first combo box (AirportID) I have:
SELECT AIRPORTS.AirportID, AIRPORTS.AirportCode
FROM AIRPORTS
ORDER BY AIRPORTS.AirportCode;

Events:
Private Sub AirportID_AfterUpdate()
TerminalID.Requery
End Sub

Combo2 (TerminalID)

SELECT TERMINALS.TerminalID, TERMINALS.TerminalName, TERMINALS.AirportID
FROM TERMINALS
WHERE ((([TERMINAL].[AirportID])=[Forms]![airline activity]![AirportID]))
ORDER BY TERMINALS.TerminalName;

Event:
Private Sub TerminalID_GotFocus()
If Len(Trim(Nz(AirportID, "") & "")) = 0 Then
MsgBox "Please Specify Airport first"
AirportID.SetFocus
Else
TerminalID.Requery
End If
End Sub
I don’t know what I am doing wrong but when I try to open the form in form view: “enter parameter value” message pop-ups and ask me for “Terminal.AirportID?”

Please help! Thanks,
O.
 
WHERE ((([TERMINAL].[AirportID])=[Forms]![airline activity]![AirportID]))

Didn't you mean [TERMINALS].[AirportID]?

Vie
 
Thank you! I corrected it and got rid of the annoying popup window with parameter value. But it's still not working right. When in a new record I click on the "AirportID" combo box, it does let me see the Airport list, but I can not select any of them. There is an errow message at the bottom of the form screen with "Control can't be edited, it's bound to AutoNumber field "AirportID." What does it mean?
Thanks!!!
 
O.,

Most everything looks good but:

I think you need to change the RowSource property of your second combo box (TerminalID) to:

SELECT TERMINALS.TerminalID, TERMINALS.TerminalName, TERMINALS.AirportID
FROM TERMINALS
WHERE (((TERMINALS.AirportID)=AirportID)) ORDER BY TERMINALS.TerminalName;

Also, in your code when you refer to a either of the combo boxes as in:

Code:
Private Sub AirportID_AfterUpdate()

TerminalID.Requery

End Sub

Make sure to include the "Me" keyword like so:

Me.TerminalID.Requery

Me is the shortcut version of an explicit reference like Forms!frmName.

Last of all, just a tiny piece of advice for future - when naming combo boxes, use the standard prefix cbo or cmb -- for example, cboAirportID and cboTerminalID. You'll be glad you did later. You won't waste time figuring out whether AirportID is referring to the field in the table or to the combo box.

Let me know if it works out!
Vie
 
larisa26, did the requery help you? If not I have had success with the me.refresh as well.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top