p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   Trying to Utilize Bound Combo Boxes with no luck! (http://p2p.wrox.com/showthread.php?t=65351)

Goobz January 18th, 2008 02:22 PM

Trying to Utilize Bound Combo Boxes with no luck!
Okay all.. Here's my deal... I have tried and tried and tried to get these to work... I'm going to post what I have done, and what I am trying to do, and see if someone can help me figure crap out...

tblBuilding - PK is BuildingIDNum - Autonumber
tblBuildingZones - FK is BuildingIDNum via

SELECT DISTINCTROW Building.BuildingIDNum, Building.Name FROM Building ORDER BY Building.BuildingIDNum;
  cboBuilding - This has Building 1, Building 2, etc. The field displaying this info is "Name" in tblBuilding.

  cboBuildingZones - This has different "zones" for Building 1, Building 2, etc., that depending on which building is chose in cboBuilding, this will populate with the "zone" - First Floor, Second Floor, Mezzanine, etc. The field displaying this info is "InBuildingLocation" in tblBuildingZones. However, the field I need to write in the underlying form table is "DN.911Zone".

I wrote the following code in AfterUpdate of the Building ID, and I'm getting a highlighted yellow on "End Sub" as soon as I try and populate my cboBuildingZones box.


Private Sub cboBuilding_AfterUpdate()
    With Me![cboZoneID]
    If IsNull(Me!cboBuilding) Then
      .RowSource = ""
      .RowSource = "SELECT [InBuildingLocation] " & _
                   "FROM tblBuildingZones " & _
                   "WHERE [BuildingIDNum]=" & Me!cboBuilding
    End If
    Call .Requery
  End With
End Sub

I hope someone can help me out either by fixing my code, or taking the 2 minutes to write what probably should be a really stupid quick entry that I just can't get my hands around!

Thanx in advance!

mmcdonal January 30th, 2008 11:28 AM

I normally do cascading combo boxes like this on the On Change event of the first combo box:

Dim iPrimaryKey As Integer
Dim sSQL As String

iPrimaryKey = Me.Combo0
sSQL = "SELECT PKID, Name FROM tblCustomer WHERE [PKID] = " & iPrimaryKey

Me.Combo2.RowSource = sSQL

Does that help?


Look it up at: http://wrox.books24x7.com

All times are GMT -4. The time now is 12:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.