link subform to other form

T

Troy Scott

Hello, I am trying to use a subform (which works great so far) to enter
data. I have a one to one relationship on the main form and sub form with
enforce referential integrity selected( cascade update/deleted selected
too). I placed a button in my subform that activates another form where the
user can enter more data. This form is on a separate table as well as the
main and subform. How can I get the popup form data to relate to the main
and subform? I checked enforce referential integrity, cascade update/delete
in my relationship but the data entered is the same for all records. HELP!

TIA

Troy
 
E

Ed Robichaud

To open another form linked to some value on your current form, include
something like the code below in the on click event that opens the new form:

'======================================================
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNewForm"
stLinkCriteria = "[MyID]=" & Forms![frmMainForm].Form![frmMysub]![MyID]

If IsNull(Forms![frmMainForm].Form![frmMysub]![MyValue]) Then
MsgBox "Enter a Record before selecting New Form"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

'=====================================================
-Ed
 
T

Troy

Why won't it link to the same record like the subform
does?

Troy

-----Original Message-----
To open another form linked to some value on your current form, include
something like the code below in the on click event that opens the new form:

'======================================================
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNewForm"
stLinkCriteria = "[MyID]=" & Forms![frmMainForm].Form! [frmMysub]![MyID]

If IsNull(Forms![frmMainForm].Form![frmMysub]! [MyValue]) Then
MsgBox "Enter a Record before selecting New Form"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

'=====================================================
-Ed

"Troy Scott mindspring.com>" <tigerweld<removebrakets> wrote in message
Hello, I am trying to use a subform (which works great so far) to enter
data. I have a one to one relationship on the main form and sub form with
enforce referential integrity selected( cascade update/deleted selected
too). I placed a button in my subform that activates
another form where
the
user can enter more data. This form is on a separate table as well as the
main and subform. How can I get the popup form data to relate to the main
and subform? I checked enforce referential integrity,
cascade
update/delete
in my relationship but the data entered is the same for
all records.
HELP!


.
 
G

Guest

Hey Ed, I tried that code but I kept getting errors.
Could you possibly be a little more help? My main form is
frmMain, my subform is frmMainSub. Would it be any better
if I place the command button just outside of the
subform? Would that help?

Thanks!

Troy

-----Original Message-----
To open another form linked to some value on your current form, include
something like the code below in the on click event that opens the new form:

'======================================================
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNewForm"
stLinkCriteria = "[MyID]=" & Forms![frmMainForm].Form! [frmMysub]![MyID]

If IsNull(Forms![frmMainForm].Form![frmMysub]! [MyValue]) Then
MsgBox "Enter a Record before selecting New Form"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

'=====================================================
-Ed

"Troy Scott mindspring.com>" <tigerweld<removebrakets> wrote in message
Hello, I am trying to use a subform (which works great so far) to enter
data. I have a one to one relationship on the main form and sub form with
enforce referential integrity selected( cascade update/deleted selected
too). I placed a button in my subform that activates
another form where
the
user can enter more data. This form is on a separate table as well as the
main and subform. How can I get the popup form data to relate to the main
and subform? I checked enforce referential integrity,
cascade
update/delete
in my relationship but the data entered is the same for
all records.
HELP!


.
 
E

Ed Robichaud

OK; the location of the command button is not that important, but see Access
help for how to reference control names on sub reports/forms. With your
names, it should be:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNewForm"
stLinkCriteria = "[MyID]=" & Forms![frmMain].Form![frmMainsub]![MyID]

If IsNull(Forms![frmMain].Form![frmMaisub]![MyID]) Then
MsgBox "Enter a Record before selecting New Form"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
'=====================================================
This should work whether the subform is a single or continuous form, as it
will use what ever record is selected in the subform, then open the new form
with the link criteria. Notr that the new form MUST have a record source
that contains [MyID].

What errors are you getting?

-Ed
(e-mail address removed)> wrote in message
Hey Ed, I tried that code but I kept getting errors.
Could you possibly be a little more help? My main form is
frmMain, my subform is frmMainSub. Would it be any better
if I place the command button just outside of the
subform? Would that help?

Thanks!

Troy

-----Original Message-----
To open another form linked to some value on your current form, include
something like the code below in the on click event that opens the new form:

'======================================================
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNewForm"
stLinkCriteria = "[MyID]=" & Forms![frmMainForm].Form! [frmMysub]![MyID]

If IsNull(Forms![frmMainForm].Form![frmMysub]! [MyValue]) Then
MsgBox "Enter a Record before selecting New Form"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

'=====================================================
-Ed

"Troy Scott mindspring.com>" <tigerweld<removebrakets> wrote in message
Hello, I am trying to use a subform (which works great so far) to enter
data. I have a one to one relationship on the main form and sub form with
enforce referential integrity selected( cascade update/deleted selected
too). I placed a button in my subform that activates
another form where
the
user can enter more data. This form is on a separate table as well as the
main and subform. How can I get the popup form data to relate to the main
and subform? I checked enforce referential integrity,
cascade
update/delete
in my relationship but the data entered is the same for
all records.
HELP!


.
 

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