Running and Printing a Report Based on a Field in a UserForm

thabounceisback

Registered User.
Local time
Yesterday, 18:44
Joined
Sep 17, 2009
Messages
31
Greetings!

I want to create a control in my User Form that runs and prints a report based on a field entered on the User Form.

Essentially, I want employees to be able to enter their ID, a date, and some other values in the form and then click a button on the form that will run and print a report that I have created.

However, the report should be based on a query that uses the employee id field to help populate the rest of the report.


Does this make sense? Is it possible?
 
First, thanks for the response. Your method seems to be working well. Second, i have run into an additional problem. When the user enters the data on the form and then clicks the open report command button, the resulting report does not include the data entered on the form. Is there some line of code that I can add, that will submit the data to the database, then run the report?

Again, thanks. I appreciate your time.
 
Anything in the form can be shown on the report by making the control source of a textbox on the Report
=Forms!formname!controlname


brian
 
I think you're looking for something like this before running the report:

DoCmd.RunCommand acCmdSaveRecord

Or

If Me.Dirty Then Me.Dirty = False
 
Ok, so I have hit a wall. Maybe I am missing something. Here is the code I have to run o the click event of the button in my form:

Code:
Option Compare Database

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

   DoCmd.RunCommand acCmdSaveRecord
    DoCmd.OpenReport "Coupons Query", , , "EE = '" & Me.Command10 & "'"

Exit_Command10_Click:
    Exit Sub

Err_Command10_Click:
    MsgBox Err.Description
    Resume Exit_Command10_Click
    
End Sub


I get this error message:
Object doesn't support this property or method.

What did I screw up?
 
The form is bound to a table or query, right? Comment out this line temporarily:

On Error GoTo Err_Command10_Click

and run the code. That should enable you to see what specific line is causing the error.
 
The form is bound to a table or query, right? Comment out this line temporarily:

On Error GoTo Err_Command10_Click

and run the code. That should enable you to see what specific line is causing the error.


Okay, so I did what you said and it made me realize that the "field" is actually a combo box. DOes that change the way I should Approach it? The Combo Box actually contains three seperate vales, but it stores the value that I am trying to use.

Basically, I have a report. And the report has a parameter. I want to use the value from the combo box to enter the parameter in the report and print it.

Am I approaching it correctly?
 
I just noticed this

DoCmd.OpenReport "Coupons Query", , , "EE = '" & Me.Command10 & "'"

It would appear you're referring to the button rather than the combo. Other than that, yes, you appear to be doing it correctly. I have a page here on the topic:

http://www.baldyweb.com/wherecondition.htm
 

Users who are viewing this thread

Back
Top Bottom