Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Pass info from one form to another

Question posted by: Jollywg (Member) on May 14th, 2008 09:01 AM
I've got a simple question, how do i pass information (lets say a name that is input in a textbox) to another form

Thanks
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
missinglinq's Avatar
missinglinq
Moderator
2,215 Posts
May 14th, 2008
11:15 AM
#2

Re: Pass info from one form to another
Depends on how you want to pass it. If you want to pass it from, say, FormA to FormB, when opening FormB, the best way would to use OpenArgs.

In your calling form:

Code: ( text )
  1. Private Sub OpenFormB_Click()
  2.   DoCmd.OpenForm "FormB", , , , , , Me.FieldToPass   
  3. End Sub

Then, in FormB:

Code: ( text )
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.     Me.WhateverField = Me.OpenArgs
  4.   End If
  5. End Sub

If both forms are already open, you could assign the data to pass to a global variable, or simply explicitly reference it as a control on the first form.

Linq ;0)>

Reply
Jollywg's Avatar
Jollywg
Member
48 Posts
May 15th, 2008
12:46 AM
#3

Re: Pass info from one form to another
[QUOTE=missinglinq]Depends on how you want to pass it. If you want to pass it from, say, FormA to FormB, when opening FormB, the best way would to use OpenArgs.

In your calling form:

Code: ( text )
  1. Private Sub OpenFormB_Click()
  2.   DoCmd.OpenForm "FormB", , , , , , Me.FieldToPass   
  3. End Sub

Then, in FormB:

Code: ( text )
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.     Me.WhateverField = Me.OpenArgs
  4.   End If
  5. End Sub

If both forms are already open, you could assign the data to pass to a global variable, or simply explicitly reference it as a control on the first form.

Linq ;0)>[/QUOTE

Thank you so much, i think that will work, but is there some way to pass multiple values such as Me.txtFirstname, Me.txtLastname??

Thanks

Reply
ADezii's Avatar
ADezii
Expert
3,697 Posts
May 15th, 2008
02:05 AM
#4

Re: Pass info from one form to another
  1. You can pass as many Values as you like in the OpenArgs Argument of the OpenForm() Method as long as you use a Common Delimiter between then.
  2. In the following example, I'll pass 4 Values (Argument 1 to Argument 4) to Form2 via the OpenArgs Argument of the OpenForm() Method:
    Code: ( text )
    1. DoCmd.OpenForm "Form2", acNormal, , , acFormEdit, acWindowNormal, "Argument 1,Argument 2,Argument 3,Argument 4"
  3. In the receiving Form, you can use the Split() Function to retrieve the variable number of Values:
    Code: ( text )
    1. Dim varOpenArgs As Variant
    2. Dim intCounter As Integer
    3.  
    4. varOpenArgs = Split(Me.OpenArgs, ",")
    5.  
    6. For intCounter = LBound(varOpenArgs) To UBound(varOpenArgs)
    7.   Debug.Print varOpenArgs(intCounter)
    8. Next
OUTPUT:
Code: ( text )
  1. Argument 1
  2. Argument 2
  3. Argument 3
  4. Argument 4

Reply
Jollywg's Avatar
Jollywg
Member
48 Posts
May 15th, 2008
07:28 PM
#5

Re: Pass info from one form to another
Thanks folks both of those posts worked like a charm, but i have one more problem that i ran into.
I need to pass the current primary key value, which is displayed in a textbox, from form1 which is made off of table Patient to form2 which is made off of table IV. Table Patient and Table IV are linked in a one to many relationship and the joining column is PatientID.

I currently have PatientID on both forms, and when i pass it the way you all showed me the status bar on form2 says "Control can't be edited; it's bound to AutoNumber field 'PatientID'. I get what this is saying, but i dont know how to "work around" it.

Ideally what this should do is in form1 the user is viewing a patient (with a unique PatientID) they click the "NewIV" button and access opens up form2 and lets the user add a new IV to the patientID that was passed to it.

I really appreciate all the help Bytes has given me over the course of this project. Thanks for any responses

Matt

Reply
ADezii's Avatar
ADezii
Expert
3,697 Posts
May 16th, 2008
02:58 AM
#6

Re: Pass info from one form to another
Quote:
Originally Posted by Jollywg
Thanks folks both of those posts worked like a charm, but i have one more problem that i ran into.
I need to pass the current primary key value, which is displayed in a textbox, from form1 which is made off of table Patient to form2 which is made off of table IV. Table Patient and Table IV are linked in a one to many relationship and the joining column is PatientID.

I currently have PatientID on both forms, and when i pass it the way you all showed me the status bar on form2 says "Control can't be edited; it's bound to AutoNumber field 'PatientID'. I get what this is saying, but i dont know how to "work around" it.

Ideally what this should do is in form1 the user is viewing a patient (with a unique PatientID) they click the "NewIV" button and access opens up form2 and lets the user add a new IV to the patientID that was passed to it.

I really appreciate all the help Bytes has given me over the course of this project. Thanks for any responses

Matt

It appears that what you need is to use the Where Argument of the OpenForm() Method and not OpenArgs, something like:
Code: ( text )
  1. DoCmd.OpenForm "Form2", acNormal, , "[PatientID] = " & Me![PatientID], acFormEdit

Reply
FishVal's Avatar
FishVal
Expert
1,675 Posts
May 16th, 2008
07:07 AM
#7

Re: Pass info from one form to another
Hi, Matt.

I guess you may get some ideas from the following threads:
Add Matching Record on Filtered Form
Datasheet to Open Child Form

Regards,
Fish

Reply
Reply
Not the answer you were looking for? Post your question . . .
178,103 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Microsoft Access / VBA Forum Contributors