Results 1 to 3 of 3
  1. #1
    pyromaniac511 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    15

    requery multiple times in same form

    I have a test form with 2 combo boxes in it. One is Brand and one is model (lets use Cisco and Linksys as the example). If brand is empty, model is empty (I like this). If I choose a brand, its models populate the model combo box (I like this). If I choose a brand and then another brand, the first brands models populate the models combo box (I do not like this). I understand I need to clear and requery but I can't seem to find the right words to google. Would one of you point me in right direction



    Here is what I have so far.

    Code:
    Private Sub cboBrands_AfterUpdate()
        
    End Sub
    Private Sub cboModels_AfterUpdate()
        Me.Query "qryModels_From_Brands"
        Me.cboBrands = ""
    End Sub
    Thanks.

  2. #2
    pyromaniac511 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    15
    I moved my SQL from its own query into the VBA and followed an example of another post. This is what I got. Please let me know if this is the right way to do it. The results seem appropriate.

    Code:
    Private Sub cboBrands_AfterUpdate()
        Dim BrandsSource As String
        BrandsSource = "SELECT [Models].[Model_ID]," & _
                        " [Models].[Model_Name]," & _
                        " [Models].[Brand_ID] " & _
                        "FROM Models " & _
                        "WHERE [Brand_ID] = " & Me.cboBrands.Value
        Me.cboModels.RowSource = BrandsSource
        Me.cboModels.Requery
    End Sub
    Private Sub cboModels_AfterUpdate()
       
    End Sub

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I'm pretty sure all you need do is Requery the cboModel control in the AfterUpdate event of the cboBrand control. ie: Me.cboModels.Requery. The RecordSource can remain static and it should still work as you would expect as long as you do the Requery.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2015, 08:48 PM
  2. Using a table in a query multiple times.
    By vgillis in forum Queries
    Replies: 1
    Last Post: 03-05-2013, 01:29 PM
  3. Run query multiple times on different tables
    By dumbledown in forum Queries
    Replies: 2
    Last Post: 03-14-2012, 05:39 AM
  4. Form_Current() running multiple times
    By caddcop in forum Forms
    Replies: 0
    Last Post: 04-01-2011, 09:00 AM
  5. Replies: 5
    Last Post: 12-10-2009, 10:33 PM

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