Link Forms with multiple fields

  • Thread starter T5925MS via AccessMonster.com
  • Start date
T

T5925MS via AccessMonster.com

Any ideas why I get a 'Type mismatch' error with this code that I using to
open a second form linking multiple fields?

Private Sub cmdUpdatePhone_Click()
On Error GoTo Err_cmdUpdatePhone_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmEdit Location Phone Numbers"
stLinkCriteria = "[Location Name]=" & "'" & Me![Location Name] & "'" And
"[Position Code]=" & "'" & Me![Position Code] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdUpdatePhone_Click:
Exit Sub

Err_cmdUpdatePhone_Click:
MsgBox Err.Description
Resume Exit_cmdUpdatePhone_Click

End Sub
 
T

T5925MS via AccessMonster.com

Nevermind. I was using quotes incorrectly. Here's the correct syntax:

stLinkCriteria = "[Location Name]='" & Me![Location Name] & "' AND [Position]
='" & Me![Position] & "'"
Any ideas why I get a 'Type mismatch' error with this code that I using to
open a second form linking multiple fields?

Private Sub cmdUpdatePhone_Click()
On Error GoTo Err_cmdUpdatePhone_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmEdit Location Phone Numbers"
stLinkCriteria = "[Location Name]=" & "'" & Me![Location Name] & "'" And
"[Position Code]=" & "'" & Me![Position Code] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdUpdatePhone_Click:
Exit Sub

Err_cmdUpdatePhone_Click:
MsgBox Err.Description
Resume Exit_cmdUpdatePhone_Click

End Sub
 
B

Beetle

the first thing that stands out is that your operator (And) is
outside of the quotes. If [Location Name] and [Position Code]
are both text data types then the following should work;

stLinkCriteria = "[Location Name]=""" & Me![Location Name] & _
""" And [Position Code]=""" & Me![Position Code] & """"
 

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