Printing the Record on the Access Form to a Report

member

New member
Local time
Today, 01:39
Joined
Nov 13, 2008
Messages
7
Hi,

Before i start, i just wanna say that i am new to Access & VBA and please excuse me if iask stupid questions.

Right here's what i need help with:

Basically I have a report which requires the user to type in the OrderID when the user attempts to open the report. This is what pops up below:

tempsui.jpg


That is fine, but what i want is a button on a form, for which when i click on it, it loads up the report 'Invoice' with the paramater requested above as the record that i am currently viewing.

For example If i am viewing a record with 'OrderID' as 10348 and i click the command button, it will open up the report with the paramater value as 10348.

I hope you get what i mean, i am getting frustrated about how to do this.
This is what i got from another website, i am probably doijng it wrong.

Code:
Private Sub cmdPrintPreview_Click()
    Dim strReportName As String
    Dim strCriteria As String

    If NewRecord Then
        MsgBox "This record contains no data. Please select a record to print or Save this record." _
             , vbInformation, "Invalid Action"
        Exit Sub
    Else
        strReportName = "Invoice"
        
        strCriteria = "[Forms]![Sales]![OrderID]= " & Me![OrderID]
        
        'strCriteria = "[Forms]![Sales]![OrderID]= " & Me![OrderID] & "'"
        'strCriteria = "[lngSalespersonID]='" & Me![lngSalespersonID] & "'"

        DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

    End If
End Sub

Any help would be much appreciated, i am sure this is very easy to do.

Thanks, i am waiting patiently for a response.
 
I would just reference "[Forms]![Sales]![OrderID]" in the reports query as a parameter and forget all of the criteria stuff in the OpenReport command....
 
I would just reference "[Forms]![Sales]![OrderID]" in the reports query as a parameter and forget all of the criteria stuff in the OpenReport command....

Sorry KenHigg i didn't understand what you meant, could you give an example.
Oh yeh i forgot to mention that the Report loads up from a query:

Field: OrderID
Table: Invoice Query
Sort: Blank
Show: Yes
Criteria: [Forms]![Sales]![OrderID]

Hope that helps
 
I have to bug out for now but if you google/search on how to reference a form control in a query as a parameter you should get some hits. Otherwise I'm sure someone else will jump in here on the forum a bit - :)
 
Sorry KenHigg i didn't understand what you meant, could you give an example.
Oh yeh i forgot to mention that the Report loads up from a query:

Field: OrderID
Table: Invoice Query
Sort: Blank
Show: Yes
Criteria: [Forms]![Sales]![OrderID]

Hope that helps

The Criteria section needs to contain the name of the form that is pulling the OrderID. You said that you copied the code from another site....you will need to reference the name of the form. For example, if the name of the form that has the button is called Sales_Form, the correct Criteria entry would be [Forms]![Sales_Form]![OrderID]. Also make sure that the name of the field that has the order number in it is called OrderID. If not, you will have to change that as well.
 

Users who are viewing this thread

Back
Top Bottom