Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generic Report Runs Only on Specific Form's Record 1

Status
Not open for further replies.

MilinPCH

Technical User
Jul 27, 2000
37
US
I know this is probably a no-brainer, but I've never done it before..I just need to see what the VBA code looks like and I can go from there...

I have a product invoice report - based on a query that asks the user for a company name and an invoice date. It works perfectly. What I want to do is create a button on the form that the user enters items to be sold. ie... when the user runs the report from this form, the questions in the query about company name and date are automatically filled in from those fields that are already present on the current form. Did I make sense?

Thanks
 
Without affecting the report's underlying recordset you can filter the report so it only displays a specific record or group of records. This is done through the use of the filter property of the report and can be passed to the report when it is called through code. Using what the button wizard gives you to open the report simply add the WHERE clause(without the word 'where') to the line that opens the report:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmPrintChecks"
stLinkCriteria = "[PrimaryKey] = " & Me.PrimaryKey
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Thanks Jerry...

have one complication - I want the report to run using two criteria - primary key and date. I can't seem to make the code use both. I've used the + , &, And, to try to add the two variables together, but I get an error. Does it matter that the DateSold field's control source is =Date() ? BTW, if I exclude the date criteria,it will work useing the CustIDNo statement.


Private Sub Command51_Click()
On Error GoTo Err_Command51_Click

Dim stDocName As String
Dim stLinkCriteria1 As String
Dim stLinkCriteria2 As String


stDocName = "SoldQueryMaster"
stLinkCriteria1 = "[CustIDNo] = " & Me.VendorShadow
stLinkCriteria2 = "[DateSold] = " & Me.DateSold

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria1 & stLinkCriteria2

 
You need the keyword 'AND'.

stLinkCriteria = '[CustIDNo] = " & Me.VendorShadow & " AND [DateSold] = " & Me.DateSold
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top