type mismatch error 13

E

Emanuel Violante

Hi everyone,
I hope that anyone can help me....
I'm trying to run the following code, but i get an type mismatch error
message.
If I use the stlinkcriteria or stlinkcriteria2 in the where condition, it
works fine, but i would like the command button to perform the two conditons

Dim stDocName As String
Dim stLinkCriteria As String
Dim stLinkCriteria2 As String
Dim stWhere As String


stDocName = "sintese_frs"

stLinkCriteria = "[gt_index]=" & "'" & Me![gt_index] & "'"
stLinkCriteria2 = "[out2_design]=" & "'" & Me![out2_design] & "'"
stWhere = stLinkCriteria And stLinkCriteria2

DoCmd.OpenForm stDocName, , , stWhere



--
Thanks,

Sorry if my english isn''t correct, but I''m from Potugal ;)

Emanuel Violante Galeano
 
B

BruceM

Try:
stLinkCriteria = "[gt_index] = """ & Me![gt_index] & """"
stLinkCriteria2 = "[out2_design] = """ & Me![out2_design] & """"
or:
stLinkCriteria = "[gt_index] = '" & Me![gt_index] & "'"
stLinkCriteria2 = "[out2_design] = '" & Me![out2_design] & "'"

Expanded for clarity:
stLinkCriteria = "[gt_index] = " " " & Me![gt_index] & " " " "
stLinkCriteria2 = "[out2_design] = " " " & Me![out2_design] & " " " "
or:
stLinkCriteria = "[gt_index] = ' " & Me![gt_index] & " ' "
stLinkCriteria2 = "[out2_design] = ' " & Me![out2_design] & " ' "

This assumes gt_index and out2_design are text fields. The first method
will work if there are apostrophes in the text of gt_index and out2_design.
The second will work if there are quote marks (") in the text. If there are
both, another approach will be needed.
 
M

Mourad

Replace

stWhere = stLinkCriteria And stLinkCriteria2

By

stWhere = stLinkCriteria & " And " & stLinkCriteria2


You may also need to replcae single quotes by double quotes
 
B

BruceM

I just realized that if you mean to combine the strings you will need to do
something like this:

stLinkCriteria = "[gt_index] = " " " & Me![gt_index] & _
" " " " AND [out2_design] = " " " &
Me![out2_design] & " " ""
or:
stLinkCriteria = "[gt_index] = ' " & Me![gt_index] & _
" ' AND [out2_design] = ' " & Me![out2_design] &
" ' "

There are other ways, but the general idea is that AND is part of the
string.
 
E

Emanuel Violante

Thanks a lot, i knew that it should be simple, it worked just fine :)
--
Thanks,

Sorry if my english isn''t correct, but I''m from Potugal ;)

Emanuel Violante Galeano
 

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