473,386 Members | 1,602 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,386 software developers and data experts.

How do I pass a value from Form1 to Form2?

I have a list of patients, each of which can have multiple insurance plans. When looking at the list of patients, I want the ability to call the form to create a new insurance policy for the patients.

The member form calls the insurance form, moves to a new record. I'd like that new record to contain the member's name (or member number) from the first form.


This has got to be a common problem from order entry systems: you move from a customer form to a new order for the customer. How does the customer number get passed from the customer form to the order form?

thanks


Dante
Nov 6 '08 #1

✓ answered by missinglinq

Just use the OpenArgs argument with the open form command.

In the original form, behind a command button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenNewPolicyForm_Click()
  2.   If Me.Dirty Then Me.Dirty = False
  3.   DoCmd.OpenForm "NewPolicyForm", , , , , , Me.MemberID
  4. End Sub
  5.  
In the form to be opened:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.     DoCmd.GoToRecord , , acNewRec
  4.     Me.MemberID = Me.OpenArgs
  5.   End If
  6. End Sub
Linq ;0)>

9 2983
missinglinq
3,532 Expert 2GB
Just use the OpenArgs argument with the open form command.

In the original form, behind a command button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenNewPolicyForm_Click()
  2.   If Me.Dirty Then Me.Dirty = False
  3.   DoCmd.OpenForm "NewPolicyForm", , , , , , Me.MemberID
  4. End Sub
  5.  
In the form to be opened:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.     DoCmd.GoToRecord , , acNewRec
  4.     Me.MemberID = Me.OpenArgs
  5.   End If
  6. End Sub
Linq ;0)>
Nov 6 '08 #2
Linq,

You're my newest hero.

Thank you so much.


Dante
Nov 6 '08 #3
missinglinq
3,532 Expert 2GB
Glad we could help!

Linq ;0)>
Nov 6 '08 #4
znyder
5
Glad we could help!

Linq ;0)>


Hi,

I'm new here.. and Im also following this discussion.
I dont have much idea about programming but I do follow instruction.
Just want to know what if I what 2 values to be pass from form1 to form2.


thanks in advance... :)
Nov 11 '08 #5
missinglinq
3,532 Expert 2GB
Passing multiple values is a little more difficult, but doable! You don't say what you want to do with these values, so I'll just assign them to variables in the newly opened form. To assign the values, in the calling form, we'll concatenate them, placing a semi-colon between them:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenFormPassing2Fields_Click()
  2.   If Me.Dirty Then Me.Dirty = False
  3.   DoCmd.OpenForm "FormToBeOpened", , , , , , Me.RecordID & ";" & Me.Rank
  4. End Sub
Then, in the receiving form, we'll use the Split() function to separate the passed values and assign them to an array. We then assign the components of the array to variables. The example does this passing two values, but it could be extended to pass as many as you need to pass.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.     SplitArgs = Split(Me.OpenArgs, ";")
  4.     FirstPassedField = SplitArgs(0)
  5.     SecondPassedField = SplitArgs(1)
  6.  End If
  7. End Sub
You can now use the variables as needed, keeping in mind the scope of the variables.

Welcome to Bytes!

Linq ;0)>
Nov 11 '08 #6
znyder
5
Hi.. Sorry for the late reply.. but I really appreciate your respond..
Thanks so much.. I got it... Im really a fan of yours.. I always end up reading your post/answer to different question.. thanks again...

znyder
Dec 4 '08 #7
Hi I have another expansion on this question I am sure you guys get once a week. I looked around quite a bit and did not see this asked anywhere. When I pass a date value It seems like openargs either crashes or sets the date to default (1899). I have tried to cast it to string and back to date a few ways but nothing seems to work. Anyone have a tip?
Oct 19 '09 #8
Well turns out a co-worker schooled me but figured id post it here for future confused people the trick is to pre-format the date :

stringhold1 = Format(dateconvert, "mm") + "/" + Format(dateconvert, "dd") + "/" + Format(dateconvert, "yyyy")

pass in argument list as :

"|" & stringhold1 & "|"

grab the value out of an open argument array and re-cast as:

newDate = DateValue(strControl2)
Oct 19 '09 #9
NeoPa
32,556 Expert Mod 16PB
Dante,

Linq has pretty well answered your question, but I'd just like to share a technique I use for data entry forms :
Instead of setting the value of any controls for a new record (which makes Access think there is a new record to create even if no other data is entered), set the .DefaultValue property of the control. This ensures the value is used if a record needs to be created, but equally allows the form to cancel the add cleanly if no data is entered.
Oct 19 '09 #10

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

Similar topics

12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
4
by: Omar Llanos | last post by:
Recently, I posted a question on how to invoke a textbox control in Form1 (parent form) from within Form2 (which is inherited from Form1). Someone suggested to pass a reference of the Form1 to the...
2
by: Chane | last post by:
hi i have doubt in how to pass values back to the called form. I have two forms, each having a textbox and a button control. First i'm run the first form and click the button, it creates object...
5
by: Jason Huang | last post by:
Hi, In Global.cs, I have public string myString="". Another 2 forms are Form1.cs, Form2.cs. How do I use the Global.cs' myString to store a string in Form1 and then pass to Form2? Thanks for...
3
by: swb76 | last post by:
I have a Object Oriented question. I got two forms - Form1 and Form2. I also got two classes Class1 and Class2 Form1 has objects Object1 - instance of Class1 and Object2 - instance of Class2. ...
3
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post by:
I have a form, Form1, that shows an instance of Form2 when a user clicks a button. On Form2, the user is to select items, Customer Names for example, from a datagrid control. When the user clicks a...
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();
8
by: AshParr | last post by:
Hi all, I have 2 forms, "Form1" & "Form2", i have a button that currently opens form2 from form1 and then hides itself: Form2 form2 = new Form2(); form2.show; this.Visible = False; and...
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....
6
by: =?Utf-8?B?Unlhbg==?= | last post by:
I am trying to pass a value from a texbox in Form1 to a textbox in Form2 using properties in VS2005 but it doesn't work; please help (project is attached). Code for Game Class: using System;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.