Linking a form a sub form

G

Guest

I have a default form with buttons on the right to open other forms for data
entering working hours. The default form is set to capture the work hours
from the button (forms).

The problem I am having is the button forms do NOT retrieve the [date] and
[name] fields from the default form so I can enter corresponding hours for
the [name] and [date].
 
A

Al Camp

Tracy,
Use the OpenArgs argument in the OpenForm command.
Say Form1 opens Form2 and Form1 has 2 dates you need to populate Form2.
(use your own object names)

Form1 button Click...
DoCmd.OpenForm "frmForm2", , , , acFormAdd, , "GetDates"

Form2 OnOpen code...
If OpenArgs = "GetDates" Then
MyDate1 = Forms!frmForm1!YourDateField1
MyDate2 = Forms!frmForm1!YourDateField2
End if
 
G

Guest

Al,
We are on the same page, but I am not very experienced, so bare with me.
"GetDates" Can this be called anything, Is it just linking the two commands
together?
MyDate1 and MyDate2 Are these my field names on Form2?
Thanks for your help
Tracy


Al Camp said:
Tracy,
Use the OpenArgs argument in the OpenForm command.
Say Form1 opens Form2 and Form1 has 2 dates you need to populate Form2.
(use your own object names)

Form1 button Click...
DoCmd.OpenForm "frmForm2", , , , acFormAdd, , "GetDates"

Form2 OnOpen code...
If OpenArgs = "GetDates" Then
MyDate1 = Forms!frmForm1!YourDateField1
MyDate2 = Forms!frmForm1!YourDateField2
End if
--
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions

Tracy said:
I have a default form with buttons on the right to open other forms for data
entering working hours. The default form is set to capture the work hours
from the button (forms).

The problem I am having is the button forms do NOT retrieve the [date] and
[name] fields from the default form so I can enter corresponding hours for
the [name] and [date].
 
A

Al Camp

Tracy,
I don't know what your object names (forms/fields) are, so I used example names.
Whatever your Form1 and Form2 are called, and whatever the fieldnames you use, you'll need
to swap them into my example code. I used the example of two date fields, but in your
case you have 1 Date and 1 Name field. Same thing... just substitute your names.
"GetDates" is just an arbitrary string value (placed in the OpenArgs argument of the
OpenForm command) that Form2 can use to decide to take an action or not... like getting
the a Date value and a Name value from Form1.
You could use any string that makes sense to you... like "GetDateAndNameFromForm1"

In English... Form1 opens from2 with a special message in the OpenArgs
("GetDateAndNameFromForm1")
Form2 can examine the OpenArgs argument that opened it, and decide whether to get the
Date and Name from Form1, or not... according to whether OpenArgs =
"GetDateAndNameFromForm1"... or not.


Substitute your form names and field name in this code.

Form1 button Click code...
DoCmd.OpenForm "frmForm2", , , , acFormAdd, , "GetDateAndNameFromForm1"
-------------------------------------------
Form2 OnOpen code...
If OpenArgs = "GetDateAndNameFromForm1" Then
YourForm2DateFieldName = Forms!frmForm1!YourForm1DateFieldName
YourForm2NameFieldName = Forms!frmForm1!YourForm1NameFieldName
End if

--
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions





Tracy said:
Al,
We are on the same page, but I am not very experienced, so bare with me.
"GetDates" Can this be called anything, Is it just linking the two commands
together?
MyDate1 and MyDate2 Are these my field names on Form2?
Thanks for your help
Tracy


Al Camp said:
Tracy,
Use the OpenArgs argument in the OpenForm command.
Say Form1 opens Form2 and Form1 has 2 dates you need to populate Form2.
(use your own object names)

Form1 button Click...
DoCmd.OpenForm "frmForm2", , , , acFormAdd, , "GetDates"

Form2 OnOpen code...
If OpenArgs = "GetDates" Then
MyDate1 = Forms!frmForm1!YourDateField1
MyDate2 = Forms!frmForm1!YourDateField2
End if
--
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions

Tracy said:
I have a default form with buttons on the right to open other forms for data
entering working hours. The default form is set to capture the work hours
from the button (forms).

The problem I am having is the button forms do NOT retrieve the [date] and
[name] fields from the default form so I can enter corresponding hours for
the [name] and [date].
 

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