Form button to create a report on record

singingshiver

Registered User.
Local time
Today, 21:15
Joined
Jul 23, 2002
Messages
51
I have a form and wish to create a button that will print a report based on this form reference. How do I do this?
 
This question gets asked nearly every day!

Have you searched the forum for this topic?

Not that you need to search!
 
Thanks for the reply.

I have read the other topics but none of them seem tailored to what I need, and the ones that are similar fail to work.

Sorry to ask a question that is frequently on this board, but I need an answer.
 
Post an example of the code you have tried, with details of the data type your trying to link etc
 
Thanks again for the post.

Here is the code I have written:

Private Sub Command172_Click()
On Error GoTo Err_Command172_Click

Dim stDocName As String
Dim stLinkCriteria

stDocName = "TEST"
stLinkCriteria = "[SFI Reference]=" & Me.Text58
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria


Exit_Command172_Click:
Exit Sub

Err_Command172_Click:
MsgBox Err.Description
Resume Exit_Command172_Click

End Sub

I am getting the following error message:

Syntax error (missing operator) in query expression '([SFI reference]=SFI 1)'

Any help is much appreciated.

:D
 
It looks as though the datatype of your critera may be wrong

If you are using a string variable in your expression you must tell access it is a string.

try replacing stLinkCriteria = "[SFI Reference]=" & Me.Text58
with stLinkCriteria = "[SFI Reference]=" & chr(34) & Me.Text58 & chr(34)

chr(34) is the ascii character for " so tells the code you are using a string.

A way to check this is to put the line
debug.print stlinkcriteria
after you have set the criteria value then look at it the immediate window. This will then show you what is being fed into the criteria statement.

Hope this helps.

Sue
 
changed it to what you said and it came back with an error message saying that there was a datatype mismatch
 
Sorry,
I have had a good look at some of my code,
Try this
leave a space before and after the =

replace stLinkCriteria = "[SFI Reference]=" & Me.Text58
with stLinkCriteria = "[SFI Reference] = " & Me.Text58

because there is no gap it has read the = as part of the text and there is no expression to evaluate.

hope this works,

If not try the debug.print and post the reply you get from the immediate / debug window.

You might also find that you needed to use the chr(34) as well, as once the expression is being evaluated the data type may be wrong.

Error messages in these situations are very unhelpful!

Do let me know what happens

Sue.
 
Try following

stLinkCriteria = "[SFI Reference]=" & "'" & Me.Text58 & "'"
 
Still not working

I have tried all the suggestions and it still isnt working.

What do you mean by trying debug.print stlinkcriteria ?? I am new to all of this.

Many thanks for your help.
 
I would of thought micsak's option would have worked.

Post your current code
 
Post your file by attachment and we 'll fix your code.
 
There is no attachment file.

Resend it to my email address
 

Users who are viewing this thread

Back
Top Bottom