Results 1 to 4 of 4
  1. #1
    yellowgelb is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    14

    Cascading combo box and list box - no data selection

    Hi
    I was reading a lot of posts but couldn't find an answer for my problem.
    I' ve got a combo box (EveRegion) and a list box (Location). After choosing a region in the combo box the list box need to show all matching locations. Both boxes are unbound. The combo box got the following row source
    Code:
    SELECT Distinct tblLocation.LocRegionRef FROM tblLocation;
    and no control source. The list box has neither a control source nor a row source. The form has no record source. I don't get an error. I am using the following code in the after update event of the combo box.



    Code:
    Private Sub EveRegion_AfterUpdate()
    Dim strRS As String
      
      strRS = "SELECT tblLocation.LocLocation FROM tblLocation"
    
    
      If Not IsNull(Me.EveRegion) Then
        strRS = strRS & " WHERE LocRegionRef = " & Me.EveRegion
      End If
     
      Me.Location.RowSource = strRS
      Me.Location.Requery
     End Sub
    When I stop the code and look at every line of the code it shows me that strRS has the correct content but the Me.argument at the end of the code is empty (Me.Location = ""). I am not sure if the error is in the code or in the settings of the properties.

    I changed and tried a lot so I just don't now what else I could try. Probably it's a simple problem just can't see it. Very happy about every advice. Thanks.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Perhaps something like:
    Code:
    Private Sub EveRegion_AfterUpdate()Dim strRS As String
      
      strRS = "SELECT tblLocation.LocLocation FROM tblLocation"
    
    
      If Not IsNull(Me.EveRegion) Then
        strRS = strRS & " WHERE LocRegionRef = '" & Me.EveRegion & "'"
      End If
     
      Me.Location.RowSource = strRS
      Me.Location.Requery  End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    yellowgelb is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    14
    Hi thanks for your answer.
    I tried to work with different amounts of quotation marks, but still couldn't figure out the solution. I simplified the code as shown to see what the actual problem is.
    When I choose a region (e.g. Desert) from the combo box (with the code below) Access is asking me "Enter parameter value" for Desert. And when I put quotation marks around Me.EveRegion it is asking for a parameter for Me.EveRegion. When I name again the same region I always get the correct answer.

    But why is Access asking for a parameter? Is this only about wrong quotation marks or do I have another bug??

    That's the code.
    Debug.Print EveRegion is the region (e.g. desert)
    Debug.Print Location is Null

    Code:
    Private Sub EveRegion_AfterUpdate()
    Me.Location.RowSource = "SELECT tblLocation.LocLocation " & " FROM tblLocation " & " WHERE LocRegionRef = " & Me.EveRegion
    Debug.Print EveRegion
    Debug.Print Location
    End Sub
    Thanks a lot for your help!!.....I forgot to mention both data entries region and location refer to a string.

  4. #4
    yellowgelb is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    14
    Hi thanks again for the advice with the quotation marks. It's working now.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-09-2014, 12:24 PM
  2. Replies: 2
    Last Post: 09-10-2013, 09:10 AM
  3. Cascading Combo / List Boxes
    By plowe in forum Programming
    Replies: 5
    Last Post: 09-07-2012, 10:55 AM
  4. Replies: 1
    Last Post: 03-30-2012, 05:59 AM
  5. Replies: 2
    Last Post: 05-27-2011, 08:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums