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).
|
|
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 )
Private Sub OpenFormB_Click() DoCmd.OpenForm "FormB", , , , , , Me.FieldToPass End Sub
Then, in FormB:
Code: ( text )
Private Sub Form_Load() If Len(Nz(Me.OpenArgs, "")) > 0 Then Me.WhateverField = Me.OpenArgs End If 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)>
|
|
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 )
Private Sub OpenFormB_Click() DoCmd.OpenForm "FormB", , , , , , Me.FieldToPass End Sub
Then, in FormB:
Code: ( text )
Private Sub Form_Load() If Len(Nz(Me.OpenArgs, "")) > 0 Then Me.WhateverField = Me.OpenArgs End If 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
|
|
May 15th, 2008 02:05 AM
# 4
|
Re: Pass info from one form to another
- 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.
- 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 )
DoCmd.OpenForm "Form2", acNormal, , , acFormEdit, acWindowNormal, "Argument 1,Argument 2,Argument 3,Argument 4"
- In the receiving Form, you can use the Split() Function to retrieve the variable number of Values:
Code: ( text )
Dim varOpenArgs As Variant Dim intCounter As Integer varOpenArgs = Split(Me.OpenArgs, ",") For intCounter = LBound(varOpenArgs) To UBound(varOpenArgs) Debug.Print varOpenArgs(intCounter) Next
OUTPUT:
Code: ( text )
Argument 1 Argument 2 Argument 3 Argument 4
|
|
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
|
|
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 )
DoCmd.OpenForm "Form2", acNormal, , "[PatientID] = " & Me![PatientID], acFormEdit
|
|
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
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
|