Syntax for stLinkCriteria

V

Veli Izzet

Hi all,

For a report from a form I have the following code

-----
Private Sub cmdCariHareket_Click()
On Error GoTo Err_cmdCariHareket_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Cari Hareketler Detay"
stLinkCriteria = "[MTID]=" & Me![MTID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_cmdCariHareket_Click:
Exit Sub

Err_cmdCariHareket_Click:
MsgBox Err.Description
Resume Exit_cmdCariHareket_Click

End Sub
-----

MTID is text, and I cannot get the report bound to MTID.

When MTID is numeric, there was no problem.

Can somebody help me with the syntax please..

Thanks for answers
 
A

Albert D.Kallal

The syntax actually need to follow sql.

eg:
select * from tblCustomers where City = 'Edmonton'

for numbers...no quotes...

select * from tblCustomers where customerID = 1345

hence, in you case:

stLinkCriteria = "[MTID] = '" & Me![MTID] & "'"

The above might be hard to read...so, I put in some extra spacess...but you
do have to remove them

stLinkCriteria = "[MTID] = ' " & Me![MTID] & " ' "

So, in effect, I simply surrounded the me![MTID] with single quotes....
 
V

Veli Izzet

Thnak you very much,

I seem to have a mental block when it comes to these extra single quotes.
 
G

Graham Mandeno

Hi Veli

A numeric value can only be a number, but a text value can include all sorts
of characters - letters, numbers, spaces, punctuation and other characters.

For this reason, you need to show where the text starts and where it ends.
This is a requirement in any computer language, for obvious reasons. In SQL
(the language of OpenReport criteria), the start and end characters are
quotes - you choose whether to use single or double quotes, but the starting
one must match the ending one.

So, using single quotes it looks like this:
stLinkCriteria = "[MTID]='" & Me![MTID] & "'"

With double quotes it looks like this:
stLinkCriteria = "[MTID]=""" & Me![MTID] & """"

Notice that you have to use two double-quotes wherever you want one to
appear in the text string. This is because VBA (the language of your code)
uses only double quotes to start and end strings. So, if you put a double
quote *inside* a string, VBA would think the string had ended. However, if
you use two together, it interprets this as meaning that the string has not
ended, but instead you just want one doublequote to appear in the string.
 

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