Results 1 to 10 of 10
  1. #1
    Huron is offline Novice
    Windows 10 Access 2003
    Join Date
    Mar 2021
    Posts
    21

    Unhappy How to change the data source (RecordSource) Combo Box...?


    How to change the data source (RecordSource) Combo Box...?

    I try to do this:

    If Me.[Combo1] = "All books" Then
    Forms![Form1]!Combo3.RecordSource = "Query1"
    Else
    Forms![Form1]!Combo3.RecordSource = "Query2"
    End If

    But it won't work…
    Attached Files Attached Files

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Make sure that your combo1 is returning the value you think it is, add a debug;

    Code:
    Debug.Print  Me.[Combo1] 
    If Me.[Combo1] = "All books" Then
          Forms![Form1]!Combo3.RecordSource = "Query1"
    Else
          Forms![Form1]!Combo3.RecordSource = "Query2"
    End If
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    combos have rowsources, not recordsources

    Since you are in the form module you can use the Me. keyword

    Me.Combo3.rowsource = ...
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    Huron is offline Novice
    Windows 10 Access 2003
    Join Date
    Mar 2021
    Posts
    21
    If Me.[Combo1] = "All books" Then
    Me.Combo3.RowSource = "Query1"
    Else
    Me.Combo3.RowSource = "Query2"
    End If

    Not work...

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Use this code. In addition to other errors, your error handler setup prevented the pertinent code from being in the execution path.

    Code:
    Private Sub Combo1_AfterUpdate()
        On Error GoTo Error_Handler
        Me!Combo2.Enabled = True
        Me!Combo2 = ""
    
    If Me.[Combo1] = "All books" Then
            Me.Combo3.RowSource = "Query1"
            Me!Combo4.Visible = False
        Else
            Me.Combo3.RowSource = "Query2"
    End If
    
    Error_Handler_Exit:
        On Error Resume Next
        Exit Sub
    Error_Handler:
        Select Case Err
            Case Else
                MsgBox "Error " & Err.Number & " (" & Err.Description & ")", vbExclamation, "Error in Sub Combo1_AfterUpdate of Form_Form1"
        End Select
        Resume Error_Handler_Exit
        Resume
    End Sub

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Huron

    Would suggest that the Form that opens on Startup is a better option.
    Attached Files Attached Files
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Huron View Post
    If Me.[Combo1] = "All books" Then
    Me.Combo3.RowSource = "Query1"
    Else
    Me.Combo3.RowSource = "Query2"
    End If

    Not work...
    "Not work" doesn't give us much to help you with.
    What doesn't work?
    Where have you put the code?
    Does it run?
    What do you have as the Row Source property of Combo3?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    Huron is offline Novice
    Windows 10 Access 2003
    Join Date
    Mar 2021
    Posts
    21
    Thank you very much... This code run properly...

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    You're welcome; and thanks for the star.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 6
    Last Post: 08-12-2016, 09:17 PM
  2. Replies: 1
    Last Post: 09-16-2015, 10:57 AM
  3. Change source of ODBC data
    By Alan Cannon in forum Access
    Replies: 1
    Last Post: 07-15-2013, 02:46 PM
  4. Change Pivot Data Source from MS Access to SQL Server
    By rjbautista20 in forum SQL Server
    Replies: 3
    Last Post: 06-24-2013, 11:36 PM
  5. Replies: 3
    Last Post: 12-11-2012, 09: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