Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing variable between forms (Access 2000)

    Don

  2. #2
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing variable between forms (Access 2000)

    I'm not 100% sure I understand teh question, but here's a stab at an answer.

    The line of code to open a form as an option to use 'openargs'. This could be set to PersonID. Then the form opens you use the openargs value to control the forms recordset.

    Depending on how you are controlling the recordset this might be easy, it might not be.

    open args is the last option on the DoCmd.OpenForm FormName, etc, etc, etc line of code.

    Hope this is what you were after

    Ian

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

    Re: passing variable between forms (Access 2000)

    If the main form is still open, you can use this:

    DoCmd.OpenReport stDocName, acPreview, , "[PersonID] = " & Forms![frmMainForm]![PersonID]

    where frmMainForm should be replaced by the actual name of the main form.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing variable between forms (Access 2000)

    Thanks very much it worked! - it picked up the PersonID perfectly

    Another snag it only works if the form was the actual form and NOT a subform, I'm afraid it has to be.

    So if I just open that form (it's called members) then it works. But if I open Household of which members is now a page on a tabbed subform, I get the message cannot find form Members.

    If I change the name to Household, then it say can't find personID

    I do appreciate your help on a real stumbling block on this database

    Michael

  5. #5
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing variable between forms (Access 2000)

    If your Print button is on your Household parent form and your personID is on your Members subform then you can reference the subform field using something like <font face="Georgia">Me!subformName.Form!personID</font face=georgia> or from somewhere else (if the Household form is still open) using something like <font face="Georgia">Forms("Household")!subformName.Form !personID</font face=georgia>. Note that 'subformName' is not necessarily the name of the subform itself (Members), but rather the name of the subform control on the parent form (Household).

    Hope this helps.

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

    Re: passing variable between forms (Access 2000)

    In addition to Tom's informative reply, you can find a comprehensive overview of how to Refer to Form and Subform properties and controls on the Access Web (and you'll find lots of other useful information there.)

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing variable between forms (Access 2000)

    Guys,

    Its working!!!!

    I can open and close the Print menu form using the code Hans gave this morning and I can print reports from the details of person on the sub form using this code from Tom and Hans:-

    Private Sub CmdPersonalInvestments_Click()
    On Error GoTo Err_CmdPersonalInvestments_Click

    Dim stDocName As String

    stDocName = "RptPersonalInvestments"
    DoCmd.OpenReport stDocName, acPreview, , "[PersonID]= " & Forms("Household")![Members].Form!PersonID

    Exit_CmdPersonalInvestments_Click:
    Exit Sub

    Err_CmdPersonalInvestments_Click:
    MsgBox Err.Description
    Resume Exit_CmdPersonalInvestments_Click

    End Sub

    Its been very frustating day - everthing worked I had just no room for the print options on the form

    With your help its now sorted, I've learnt a lot and I'm very grateful.

    Thanks a million

    Michael

    Ps and thank for pointing me to the Access web
    M

Posting Permissions

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