singingshiver
03-25-2003, 05:34 AM
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?
|
View Full Version : Form button to create a report on record singingshiver 03-25-2003, 05:34 AM 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? KevinM 03-25-2003, 06:29 AM This question gets asked nearly every day! Have you searched the forum for this topic? Not that you need to search! singingshiver 03-25-2003, 07:17 AM 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. Rich 03-25-2003, 07:26 AM Post an example of the code you have tried, with details of the data type your trying to link etc singingshiver 03-25-2003, 07:37 AM 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 suepowell 03-25-2003, 08:17 AM 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 singingshiver 03-25-2003, 08:30 AM changed it to what you said and it came back with an error message saying that there was a datatype mismatch suepowell 03-25-2003, 08:47 AM 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. micsak 03-27-2003, 02:50 AM Try following stLinkCriteria = "[SFI Reference]=" & "'" & Me.Text58 & "'" singingshiver 03-27-2003, 04:16 AM 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. KevinM 03-27-2003, 04:19 AM I would of thought micsak's option would have worked. Post your current code micsak 03-27-2003, 04:23 AM Post your file by attachment and we 'll fix your code. singingshiver 03-27-2003, 05:27 AM file is too big micsak 03-27-2003, 05:30 AM There is no attachment file. Resend it to my email address micsak 03-27-2003, 05:31 AM There is no attachment file. Resend it to my email address micsak@itsi.gr |