Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using VBA to set Recordsource of a subform (Access 2000)

    How do I set the record source of a subform using VBA? I will be setting the recordsource equal to a string variable that is SQL code.

    Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using VBA to set Recordsource of a subform (Access 2000)

    I assume that you want to set the record source from the main form.

    Open your main form in design view.
    Click once on the subform to select it.
    The caption of the Properties window, and of course the Name property, will display the name of the subform as a control on the main form. This is not necessarily the same as the name of the subform in the database window. You need the control name for the following. Let's say it is sbfTest for illutration purposes.
    The code to set the record source looks like this:

    Dim strSQL As String
    strSQL = "SELECT ..."
    Me.sbfTest.RecordSource = strSQL

  3. #3
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using VBA to set Recordsource of a subform (Access 2000)

    I can not get this code to work. I have tried using both the control name and the subform name. I get the following error.

    Complie Error
    Method or data member not found

    It is telling me that ".Recordsource" is invalid.

    Mike

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using VBA to set Recordsource of a subform (Access 2000)

    Oops, my bad. It shouild have been

    Me.sbfTest.Form.RecordSource = strSQL

  5. #5
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using VBA to set Recordsource of a subform (Access 2000)

    Thanks,

    That did the trick.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •