Results 1 to 2 of 2
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    changing recordsource

    All, using 2010. I have a 3 forms with the same fields. I have an unbound field to filter through the records so I can make notes. I would like to change the record source based of the command button I choose to change the recordsource because the forms are based on a query. This would prevent the user from having to go into and out of forms. The memo field is a subform so it should not change because each query has the same key fields to link the records. So far I have the following code:
    Code:
    Forms!frmCustomers.RecordSource = "Customers"
    Something is missing. Please help. Thanks

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    I have used a similar system, on my forms as there are too many 'selection' options to make a static query viable.

    I construct the SQL in VB and then assign it as the recordsource
    For the command button
    Code:
    dim rsql as string
    
    if commandbutton.caption="Caption for default" then
        rsql="SELECT * from tbl_example where Primary_ID is not null ORDER BY Primary_ID ASC"
        me.recordsource=rsql
        commandbutton.caption="Caption for alternative"
    
    elseif commandbutton.caption="Caption for alternative"  then
    rsql="SELECT * from tbl_example2 where Secondary_ID is not null ORDER BY Secondary_ID ASC"
    me.recordsource=rsql
    commandbutton.caption="Caption for default"
    endif
    In your case you may wish to switch the if criteria from a commandbutton caption to a list or combobox valuee, but hopefully it should point you in the right direction.
    Last edited by R_Badger; 05-02-2013 at 06:11 AM. Reason: Hadn't finished

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

Similar Threads

  1. RecordSource issue?
    By glen in forum Forms
    Replies: 25
    Last Post: 07-31-2012, 09:34 AM
  2. RecordSource sql stays
    By rashima in forum Forms
    Replies: 0
    Last Post: 04-20-2012, 05:56 AM
  3. Replies: 8
    Last Post: 03-16-2012, 11:04 AM
  4. RecordSource help
    By mann2x in forum Access
    Replies: 3
    Last Post: 10-05-2010, 06:44 PM
  5. Changing A Report Recordsource from a form
    By warrenjburns in forum Reports
    Replies: 0
    Last Post: 04-09-2009, 05:38 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