linking forms with common elements

G

Guest

I want to create an event procedure where I can double click on a field and
it will open another form and find the corresponding information. I can
easily accomplish this if I am only linking one field, but I need to link two
fields. Both of these fields exist on the primary form and the form I want
to link to, but the command that I have written only seems to link to one of
the items. The following is how I have the event written now.

_______
Private Sub txtUPIN_DblClick(Cancel As Integer)

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInv_1"

stLinkCriteria = "[strUPIN]=" & "'" & Me![strUPIN] & "'"
stLinkCriteria = "[strReviewID]=" & "'" & Me![strReviewID] & "'"
DoCmd.close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_txtUPIN_Click:
Exit Sub

Err_txtUPIN_Click:
MsgBox Err.Description
Resume Exit_txtUPIN_Click

End Sub
__________
What do I need to do differently to link both of the fields [strUPIN] and
[strReviewID] in both forms?

Thanks!
 
G

Guest

Hi Don...

Easy fix for this one. You need to use the keyword AND to join the two bits
of information, like this:

stLinkCriteria = "[strUPIN]='" & Me![strUPIN] & "' AND [strReviewID]='" &
Me![strReviewID] & "'"

Also, your docmd.close will close the form you are viewing before opening
the other one... try this if you want your form to close:

DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.close acform, me.name

Hope that helps.

Damian.
 
G

Guest

Thank you for the information. I had previously tried this and I receive a
compile error/syntax error message. I tried it again just to be sure but I
still receive the error.
--
Thanks!


Damian S said:
Hi Don...

Easy fix for this one. You need to use the keyword AND to join the two bits
of information, like this:

stLinkCriteria = "[strUPIN]='" & Me![strUPIN] & "' AND [strReviewID]='" &
Me![strReviewID] & "'"

Also, your docmd.close will close the form you are viewing before opening
the other one... try this if you want your form to close:

DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.close acform, me.name

Hope that helps.

Damian.

Don said:
I want to create an event procedure where I can double click on a field and
it will open another form and find the corresponding information. I can
easily accomplish this if I am only linking one field, but I need to link two
fields. Both of these fields exist on the primary form and the form I want
to link to, but the command that I have written only seems to link to one of
the items. The following is how I have the event written now.

_______
Private Sub txtUPIN_DblClick(Cancel As Integer)

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInv_1"

stLinkCriteria = "[strUPIN]=" & "'" & Me![strUPIN] & "'"
stLinkCriteria = "[strReviewID]=" & "'" & Me![strReviewID] & "'"
DoCmd.close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_txtUPIN_Click:
Exit Sub

Err_txtUPIN_Click:
MsgBox Err.Description
Resume Exit_txtUPIN_Click

End Sub
__________
What do I need to do differently to link both of the fields [strUPIN] and
[strReviewID] in both forms?

Thanks!
 

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