Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2003
    Location
    Canberra, ACT Australia
    Posts
    53

    Angry Unanswered: changing record source programmatically

    I have an access form (Form A) with 2 command buttons on it. Button1 and Button2

    Click Button1 and a second form (formB) opens. FormB also has a subform(SubFormB), which also has a sub form on it (SubSubformB). The record source for FormB is a table (Borrowers), and is linked to the child form (subformB) by fields phone1 and surname.

    This is working ok.

    Click Button2 and a third form (formC) opens. FormC also has a subform(SubFormB), which also has a sub form on it (SubSubformB as above, the same form). The record source for FormC is a query (AddNewwindow), and is linked to the child form (subformB) by fields phone1 and surname. The criteria field in the query picks up on a field on form A, and shows in the query as forms!FormA.quotenumber

    This also working well.

    What I want to do is to be able to click either Button1 or Button2, and accordingly change the record source.

    I have attempted to code this with no luck. If I change the record source in the properties box for FormB ( and get rid of formC completely which is what I want to do) it works well. That is if I change the record source to either the table OR the query it does what I want. I have attempted a variety of syntax, all to no avail.

    I have concentrated on coding on the Button2 click action.

    Help would be appreciated.

  2. #2
    Join Date
    Aug 2002
    Location
    Melbourne, Australia
    Posts
    111
    Put this behind your button

    Code:
    Me.RecordSource = "YourTablesName" ( or Query name)
    Simple as that.
    Regards,



    John A

  3. #3
    Join Date
    Jul 2003
    Location
    Canberra, ACT Australia
    Posts
    53
    the me. refers to the currently opened form. The currently opened form has the button on it, but the record source refers to the form to be opened.

    I have tried such things as:

    stform = "formname"
    stcriteria = me.fieldname

    docmd.openform stform,,,stcriteria

    etc.

    Appreciate the thought. I may not have explained it clearly.

  4. #4
    Join Date
    Aug 2002
    Location
    Melbourne, Australia
    Posts
    111
    Have a look at the attached sample.
    Attached Files Attached Files
    Last edited by ansentry; 01-31-06 at 09:36.
    Regards,



    John A

  5. #5
    Join Date
    Aug 2002
    Location
    Melbourne, Australia
    Posts
    111
    Sorry attached it twice I have removed the attachment from here
    Last edited by ansentry; 01-31-06 at 09:34.
    Regards,



    John A

  6. #6
    Join Date
    Jul 2003
    Location
    Canberra, ACT Australia
    Posts
    53
    Cheers. Very neat response, and turned the grey matter. I ended up using openArgs, with select case to change recordsource.

    many thanks

  7. #7
    Join Date
    Jul 2003
    Location
    Canberra, ACT Australia
    Posts
    53
    Cheers. Very neat response, and turned the grey matter. I ended up using openArgs, with select case to change recordsource.



    many thanks

  8. #8
    Join Date
    Jul 2003
    Location
    Canberra, ACT Australia
    Posts
    53
    many thanks, Very neat sltn, turned the grey matter. i ended up using openargs with a select case on the FormB in the form onopen whereby the case allows selection of recordsource. Still not working 100% but now probs getting subforms working correctly, hopefully nothing major.

    cheers

Posting Permissions

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