searching usinig unbound form in visual basic

P

patrick tz

I am trying to search my data table based on two or more search criteria that
will open a seperate form with a command button. I have already created a
unbound form and added a command button that will allow me to search based on
a single field and have viewed the code in vba and tried to add in a second
serch field and when i try the command button i recieve a "mismatch type"
error message.

I am able to change the fields around and get the command button based on a
single field but when i add in a second field it will not work.

this is what i have so far:

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim STLINKCRITERIA1 As String

stDocName = "MCHUGH"

STLINKCRITERIA1 = "[FNAME]=" & "'" & Me![first] & "'"
stLinkCriteria = "[LNAME]=" & "'" & Me![last] & "'"
DoCmd.OpenForm stDocName, , , STLINKCRITERIA1

Exit_Command18_Click:
Exit Sub

Err_Command18_Click:
MsgBox Err.Description
Resume Exit_Command18_Click

End Sub

thank you for your help
 
M

Martin J

Your just sending criteria1! what about criteria?
DoCmd.OpenForm stDocName, , , STLINKCRITERIA1
You need to concatenate the 2 criteria and put an "and" in between like
"[fn]='" & me![first] & "' and [ln]=...."
--
HTH
Martin J


patrick tz said:
I am trying to search my data table based on two or more search criteria that
will open a seperate form with a command button. I have already created a
unbound form and added a command button that will allow me to search based on
a single field and have viewed the code in vba and tried to add in a second
serch field and when i try the command button i recieve a "mismatch type"
error message.

I am able to change the fields around and get the command button based on a
single field but when i add in a second field it will not work.

this is what i have so far:

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim STLINKCRITERIA1 As String

stDocName = "MCHUGH"

STLINKCRITERIA1 = "[FNAME]=" & "'" & Me![first] & "'"
stLinkCriteria = "[LNAME]=" & "'" & Me![last] & "'"
DoCmd.OpenForm stDocName, , , STLINKCRITERIA1

Exit_Command18_Click:
Exit Sub

Err_Command18_Click:
MsgBox Err.Description
Resume Exit_Command18_Click

End Sub

thank you for your help
 
T

tansey tz

I changened: stLinkCriteria = "[LNAME]=" & "'" & Me![last] & "'"

to: stLinkCriteria = "[FNAME]=" & "'" & Me![first] & "'" And "[LNAME]=" &
"'" & Me![last] & "'"

and i get a: "type mismatch" error

Martin J said:
Your just sending criteria1! what about criteria?
DoCmd.OpenForm stDocName, , , STLINKCRITERIA1
You need to concatenate the 2 criteria and put an "and" in between like
"[fn]='" & me![first] & "' and [ln]=...."
--
HTH
Martin J


patrick tz said:
I am trying to search my data table based on two or more search criteria that
will open a seperate form with a command button. I have already created a
unbound form and added a command button that will allow me to search based on
a single field and have viewed the code in vba and tried to add in a second
serch field and when i try the command button i recieve a "mismatch type"
error message.

I am able to change the fields around and get the command button based on a
single field but when i add in a second field it will not work.

this is what i have so far:

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim STLINKCRITERIA1 As String

stDocName = "MCHUGH"

STLINKCRITERIA1 = "[FNAME]=" & "'" & Me![first] & "'"
stLinkCriteria = "[LNAME]=" & "'" & Me![last] & "'"
DoCmd.OpenForm stDocName, , , STLINKCRITERIA1

Exit_Command18_Click:
Exit Sub

Err_Command18_Click:
MsgBox Err.Description
Resume Exit_Command18_Click

End Sub

thank you for your 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