Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    660

    Unanswered: how to change the record source in access

    I have a source code that will open a form that will be use many times, but the record source are different, how to write a code to change the record source. Thanks.
    For example, in my source code, i have:

    stDocName='Search'
    DoCmd.OpenForm stDocName, acNormal,........
    how to add code to change the record source fo Search FORM.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Me.RecordSource="<Query Name> -or- SELECT * FROM SomeTable ..."

    You can pass in the record source name/string as an argument to the form also ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Mar 2004
    Posts
    660
    I try that, but actually the Search Form when i designed already has record source, so when i write code like this, please take a look,

    DoCmd.OpenForm 'Search'
    Me.RecordSource = qrySearchByName

    It will open the Search form that has old record source first, then change the record source, As the old record source doesn't has any criteria, but the new qury has criteria. Can you help?

    Many thanks.

  4. #4
    Join Date
    Mar 2004
    Posts
    660
    I try that, but actually the Search Form when i designed already has record source, so when i write code like this, please take a look,

    DoCmd.OpenForm 'Search'
    Me.RecordSource = qrySearchByName

    It will open the Search form that has old record source first, then change the record source, As the old record source doesn't has any criteria, but the new qury has criteria. I would like to change the record source before opening the Search FORM

    Can you help?

    Many thanks.

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by yyu
    I try that, but actually the Search Form when i designed already has record source, so when i write code like this, please take a look,

    DoCmd.OpenForm 'Search'
    Me.RecordSource = qrySearchByName

    It will open the Search form that has old record source first, then change the record source, As the old record source doesn't has any criteria, but the new qury has criteria. I would like to change the record source before opening the Search FORM

    Can you help?

    Many thanks.
    Try setting the RecordSource within the Form's Open or Load event ...
    Back to Access ... ADO is not the way to go for speed ...

Posting Permissions

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