How to code a Command button to display current form to a report

morpheus

Registered User.
Local time
Today, 02:15
Joined
Jun 15, 2000
Messages
11
Two part question:
1)I am working on a Quality Control database to store test data on over 1700 different products. Right now I have a form designed that has a set of three tab controls so the end user could switch the three sets of test data subforms that are linked to the main product information, thus displaying just that products data.

I want to add a command button that opens up a report displaying the data information for the product displayed. I have yet to find out how i can do this without having a popup dialog asking me what Product ID I want. I want to be able to eliminate this step and go straight into the report with the currently displayed information.


2) Now once that is accomplished how do I have the report ONLY display and print the last 30 chronological entries by date...NOT the last 30 entered, and sort them in ascending order?

I think i am going gray over here trying to figure it out.

Currently this is the coding that i have:

Private Sub GoToDataCompReport_Click()
On Error GoTo Err_GoToCompReport_Click
DoCmd.OpenReport "rptDataComp", acPreview, , "[MixID]=[Forms]![frmDataComp]![MixID]"

Exit_GoToDataCompReport_Click:
Exit Sub

Err_GoToDataCompReport_Click:
MsgBox Err.Description
Resume Exit_GoToDataCompReport_Click

End Sub
 
The easiest way to do this is to use a quick module. Make a module, then dim a public variable, like:

public gProduct_ID as string

Then, make a function to return the value:

public function Get_Product_ID ()
Get_Product_ID=gProduct_ID
end sub

Then in your query for your report, add the criteria for the product id to "=Get_Product_ID ()". Assign the value before calling the report.

I use this all the time for filters.
 

Users who are viewing this thread

Back
Top Bottom