Opening form from form and passing value

L

LanWanMan

He Everyone.

Writing DB to record accident claims. I have a table for the Claims with
things like claimnumber, date, etc. Then I want to record the first and
last name of each person involved and then populate the details for that
person in another table. I think I need to do it with parent form / sub
form, however, I don't know how to:

1. Make the subform a popup form, not embedded in main form
2. Pass key values from the main form into the subform when opened
3. Pass new values back to parent form when subform is closed with command
button.

If anyone can help, please reply to the newsgroup,

Thanks,

Michael
 
C

Col

Create a public variable to hold the return value.
Put the key values in a string
Open the subform (Docmd.Openform "subform",,,,,acDialog,KeyValuesInString)
The subform OnOpen event should read the OpenArgs which contain the
KeyValues.
Put the return values into the public variable(s) before closing the
subform.
Regards
Col
 
L

LanWanMan

Col,

Thanks for the insight. I understand the concept, but am a little shakey in
the code. Do I:

Create public variable in general declarations? "Public mytext as string"
If that line is correct, what would be the syntax of the "Docmd.Openform"
line.
On the OnOpen event, what is the correct code to read the openargs?

Thanks in advance for your help.

Regard,

Michael
 
L

LanWanMan

Col,

I have working code to pass multiple values from "form1" to
"form2".....which is not a subform, but now, all I need to do is pass a
value from the "form2" into a field on "form1" when I close "form2" with
cmd button or other.

Thanks,

Michael
 
L

Larry Linson

LanWanMan said:
. . . now, all I need to do is pass a value
from the "form2" into a field on "form1"
when I close "form2" with cmd button
or other.

If Form2 will always be opened by the same Form, and assuming the name of
that Form is "Form1" and you want to store the value from variable "MyValue"
into TextBox "Text1" on "Form1", then

1. Be sure to leave Form1 open

2. Replace the "assumed names" with the names of
your form, text box, and variable in the following line

Forms!Form1!Text1 = myValue

3. Put this code in the Close event of Form2.

If it will be opened by different Forms, you can also pass the Form's Name,
but that will make deciphering your OpenArgs a little more complex, so you
don't want to do it unless it is needed.

Larry Linson
Microsoft Access MVP
 
L

LanWanMan

Larry,

Thanks. That works like a charm. That is one hurdle, but perhaps you
could help with the next step. I get this working, I can complete this darn
thing:

Claims table, among other fields has:

ClaimID

EmpID1
EMPLast1
EMPFirst1

EmpID2
EmpLast2
EmpFirst2

I have 8 of these employee ID, last and first fields in the "Claims" table.

EmpLast1 is bound to a combo box in "form1" which "after update" opens
"form2" and passes "ClaimID", "EmpLast1" and "EmpFirst1" into "form 2".
"Form2" records additional info on the employee and also generates an
"EmpID", which "on close", passes that value back to "EmpID1" on "form1". I
need to do this for all 8 combo boxes. I know I could do it with 8 seperate
"form2" copies, but I was hoping you might know a way to do it with a loop.

Any help you can provide is greatly appreciated.

Thanks again,

Michael
LanWanMan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top