473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Pass info from one form to another

158 100+
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
6 2818
missinglinq
3,532 Expert 2GB
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
Jollywg
158 100+
[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
8,834 Expert 8TB
  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
Jollywg
158 100+
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
8,834 Expert 8TB
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
2,653 Expert 2GB
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

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

Similar topics

11
by: Vanessa | last post by:
Hi, I would like to know whether there's any way for me to pass an object by reference to another form? Regards Vanessa
3
by: Don Seckler | last post by:
I have a data entry form called Draw. This form is used to enter data in the table called Draw. The table has the following fields: WholesalerID, MagID, IssueID, CopiesDist, and the index is...
5
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
3
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around...
5
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the...
3
by: Martin | last post by:
I have a calendar form that sends the inputted date back to a text box . Using the GET method, I would like to pass the date as a variable to another asp page. How do I do this? Thanks.
7
by: Boki | last post by:
Hi All, I can't pass data to another form: in form2: private void button1_Click(object sender, EventArgs e) { Form1 form_copy = new Form1();
12
by: Kevin Blount | last post by:
I'm having a very odd issue, that arose this morning after working fine yesterday... here's a very simple script: 1: <?php 2: $test = $_GET; 3: echo "Hello" . $test . "<p>"; 4: ?>
13
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.