Results 1 to 7 of 7
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Passing Data Between Forms (A2K SR1)

    Form 1 contains a combo box bound to column 1. After the user makes a selection in the combo box, they press a command button that saves the combo box selection made as variable C and then launches Form 2.

    I want to pass the value C to a combo box in Form 2 such that when Form 2 opens, the combo box selection in Form 2 is set to C. I can't seem to get this to work. Any ideas??

    (One last thing, I can't use the Form 2 Combo Box default settings as the form has other uses)
    Regards,

    Gary
    (It's been a while!)

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

    Re: Passing Data Between Forms (A2K SR1)

    You can pass the value of C in the OpenArgs argument to DoCmd.OpenForm.

    The OnLoad or OnOpen event of the second form can inspect OpenArgs. If it's empty, the form was opened by itself or from somewhere else, so just continue with the rest of the OnLoad/OnOpen. Otherwise, set the value of the combo box to OpenArgs.

    So, in OnLoad or OnOpen of the second form:

    If OpenArgs <> "" Then
    cboSomething = OpenArgs
    End If

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Passing Data Between Forms (A2K SR1)

    In your event code in Form 1 that opens Form2, you could just add a line of code (after your .OpenForm line) that just set the value of that combo box in form 2. Something like:[pre]
    Forms!form2!comboboxname = Forms!forms1!combboxname[pre]
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Passing Data Between Forms (A2K SR1)

    Mark,

    I tried something like this but kept getting an error message (Run Time 2450, ...can't find document). The code is posted below. BTW, what does the [pre] do?

    Dim stForm As String 'Name of Report Form
    Dim stDocName As String ' Name of form to open
    Dim stLinkCriteria As String

    'GET DATA FROM CURRENT FORM

    stForm = "FORM - Program Report" ' Set to current form
    C = Me.SelectClinSlin.Column(0) ' Get value from current form
    MsgBox C ' Test to see if value is selected, it is
    DoCmd.Close

    'OPEN NEW FORM
    stDocName = "DASHBOARD - BY CLIN"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    ' Set listbox value to C

    Forms!stDocName!SelectClinSlin.Value = C
    'Forms!stDocName!SelectClinSlin.Column(0)

    End Sub

    I have tried both
    Forms!stDocName!SelectClinSlin.Value = C
    Forms!stDocName!SelectClinSlin.Column(0)
    and receive the runtime error both ways indicating that the form can't be found.

    Help... <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Regards,

    Gary
    (It's been a while!)

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Passing Data Between Forms (A2K SR1)

    I was looking at this but unsure how to do it. I will try this as well to see if I can get it to work.

    Thanks
    Regards,

    Gary
    (It's been a while!)

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Passing Data Between Forms (A2K SR1)

    This is failing because you are using the wrong syntax to refer to a form. You used this: <pre> Forms!stDocName!SelectClinSlin.Value = C</pre>

    This told Access to look for a form named "stDocName"! If you want it to look for the form name contained in variable stDocName, you must use this syntax:<pre>Forms(stDocName)!SelectClinSlin.Value= C</pre>

    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. #7
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Passing Data Between Forms (A2K SR1)

    Thanks.
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

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