0
votes

I have a button on my form that creates a print preview of my report. I can not get it to open on the same record as the current form. Instead it opens to the first record. They are both on the same query. I tried both macros and VBA. I'm new to access and cant understand how to get my records to be the same and print preview just the record I had open in my form

Here's my VBA code,I get error saying "no messsage for this error"

    DoCmd.OpenReport "Moisture", acViewPreview, , "[Order Number]= " & [Order Number]
2
Is this code behind the form that has the [Order Number] field? What event is the code in? Are you trying to open report on record that ws just created?June7
yes it is behind the form with that field. the event was on the click of the button. part of the record would have just been created. it pulls the correct info but not on the right record rather it lists all of themNormX
What is the data type of Order Number? String or number?Parfait
If [Order Number] is a text field then the parameter requires text delimiters. I use apostrophe: "[Order Number] = '" & [Order Number] & "'". However, might need to first run code that commits record edits to table. Also, recommend no spaces nor punctuation/special characters (underscore only exception) in naming convention.June7

2 Answers

1
votes

Try:

DoCmd.OpenReport "Moisture", acViewPreview, , "[Order Number]=""" & [Order Number] & """"
0
votes

This may not be the best way but i solved this issue by creating a query for the report that only displayed the record source that was open with in my form. I passed the following in my criteria for my primary key in the query.

   [Forms]![NameOfForm]![PrimaryKey] 

thus only displaying that specific fields for that Primary key opened in the form and nothing else.