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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating reports from forms 1

Status
Not open for further replies.

riddler83

Technical User
Apr 20, 2006
46
IE
Complete n00b to access so Im havent really got much idea on how to work its little intricacies yet.
What I have is a form which runs a query, the end user selects a department from a drop down, then enters a start and end date and the query runs, giving them the output they require. What Im wondering is how to get this to output directly to a report so it can be viewed easier.
The problem Im having is that Im not sure how to use the combo box as a link to the report. I can pass the dates in via the query, but with so many departments a combo/list box is vital here. Any ideas???
 
If the query is picking up the information from your form, just creating a report based on the query should work.
 
Ive tried that, but I get the error message
Forms!DeptAbs!cbodept
when I run the report.
I figure its looking for the form to enter the information, but dont know how to link this
 
When you are running the query, you have the form open yesno? So do the same thing with the report. It is best to use the Command Button wizard to create a button on your form to open the report.
 
What I have the form doing at the mo is the following

Private Sub cmdOK_Click()
DoCmd.OpenQuery "DeptAbsQuery", acViewNormal, acEdit
DoCmd.Close acForm, "DeptAbs"
End Sub

If I change this so the 2nd line reads
DoCmd.OpenForm "AbsencesbyDepartment", acViewNormal, acEdit
it ignores the combo box entry

Im completely green as I said so Im a bit lost with why its not working
 
It is easiest to use the wizard at first, it would produce something like this:
Code:
Private Sub cmdViewReport_Click()
On Error GoTo Err_cmdViewReport_Click

    Dim stDocName As String

    stDocName = "rptReport1"
    DoCmd.OpenReport stDocName, acPreview

Exit_cmdViewReport_Click:
    Exit Sub

Err_cmdViewReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdViewReport_Click
End Sub
This needs to be run from the open form, so that the data in the combo and date textboxes can be picked up by the query on which the report is based. You can hide the form and close it with the close event of the report, if you wish.
This line:
[tt]DoCmd.OpenForm "AbsencesbyDepartment", acViewNormal, acEdit[/tt]
Is for opening a form, not a report.
You will need to comment out ('):
[tt]DoCmd.Close acForm, "DeptAbs"[/tt]
Because you need the form open.
 
Excellent, thats working perfect now. Thanks a million, was wrecking my head far too much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top