Multiple linkcriteria

  • Thread starter Thread starter Bob Quintal
  • Start date Start date
B

Bob Quintal

I'm trying to open a form via command button and show a
specific record in the main form as well as a specific record
in it's subform.

Here's my code:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSingleContactPrint"

stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND "
[Forms]![frmInitialContactDetails]![DateOfContact] = " & Me!
[DateOfContact] "


DoCmd.OpenForm stDocName, , , stLinkCriteria



frmInitialContactDetails being the subform within
frmSingleContactPrint. All I get is a message saying access
can't find frmInitialContactDetails.

Can someone point out where I have went wrong with this code
or suggest a better way of using multiple link criteria?
to refer to a control on a subform you need to go through the
parent form.



stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND "
subformcontrolname.form!DateOfContact = " & Me!
[DateOfContact] "

note that subformcontrolname may be the same as
[frmInitialContactDetails], but it may not. You will find the name
on the properties for the subbform, frmInitialContactDetails will
definitely be in the source object property, but you will want the
name property.
 
I'm trying to open a form via command button and show a specific
record in the main form as well as a specific record in it's subform.

Here's my code:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSingleContactPrint"

stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND "
[Forms]![frmInitialContactDetails]![DateOfContact] = " & Me!
[DateOfContact] "


DoCmd.OpenForm stDocName, , , stLinkCriteria



frmInitialContactDetails being the subform within
frmSingleContactPrint. All I get is a message saying access can't find
frmInitialContactDetails.

Can someone point out where I have went wrong with this code or
suggest a better way of using multiple link criteria?
 
Assuming that DateOfContact is a Date data type, you need to delimit the
date with # characters. You also need to guarantee that it'll be in a format
Access can recognize:

stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND " & _
"[Forms]![frmInitialContactDetails]![DateOfContact] = " & _
Format(Me![DateOfContact], "\#yyyy\-mm\-dd\#")
 
Sorry, that's incorrect.

You can't specify a form field in the Criteria statement: you can only refer
to fields in the form's underlying RecordSource.

stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND " & _
"[DateOfContact] = " & _
Format(Me![DateOfContact], "\#yyyy\-mm\-dd\#")


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Douglas J. Steele said:
Assuming that DateOfContact is a Date data type, you need to delimit the
date with # characters. You also need to guarantee that it'll be in a
format Access can recognize:

stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND " & _
"[Forms]![frmInitialContactDetails]![DateOfContact] = " & _
Format(Me![DateOfContact], "\#yyyy\-mm\-dd\#")


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


davea said:
I'm trying to open a form via command button and show a specific
record in the main form as well as a specific record in it's subform.

Here's my code:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSingleContactPrint"

stLinkCriteria = "[PersonID]=" & Me![PersonID] & " AND "
[Forms]![frmInitialContactDetails]![DateOfContact] = " & Me!
[DateOfContact] "


DoCmd.OpenForm stDocName, , , stLinkCriteria



frmInitialContactDetails being the subform within
frmSingleContactPrint. All I get is a message saying access can't find
frmInitialContactDetails.

Can someone point out where I have went wrong with this code or
suggest a better way of using multiple link criteria?
 
Back
Top