By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,425 Members | 2,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,425 IT Pros & Developers. It's quick & easy.

Pass info from one form to another

100+
P: 158
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
May 14 '08 #1
Share this Question
Share on Google+
6 Replies


missinglinq
Expert 2.5K+
P: 3,532
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenFormB_Click()
  2.   DoCmd.OpenForm "FormB", , , , , , Me.FieldToPass    
  3. End Sub
  4.  
Then, in FormB:

Expand|Select|Wrap|Line Numbers
  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)>
May 14 '08 #2

100+
P: 158
[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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenFormB_Click()
  2.   DoCmd.OpenForm "FormB", , , , , , Me.FieldToPass    
  3. End Sub
  4.  
Then, in FormB:

Expand|Select|Wrap|Line Numbers
  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
May 15 '08 #3

ADezii
Expert 5K+
P: 8,638
  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:
    Expand|Select|Wrap|Line Numbers
    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:
    Expand|Select|Wrap|Line Numbers
    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:
Expand|Select|Wrap|Line Numbers
  1. Argument 1
  2. Argument 2
  3. Argument 3
  4. Argument 4
May 15 '08 #4

100+
P: 158
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 15 '08 #5

ADezii
Expert 5K+
P: 8,638
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:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Form2", acNormal, , "[PatientID] = " & Me![PatientID], acFormEdit
May 16 '08 #6

FishVal
Expert 2.5K+
P: 2,653
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
May 16 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.