Creating a report from a drop down list

arttienet

Registered User.
Local time
Today, 05:46
Joined
Aug 21, 2006
Messages
14
Hello All,
I have a form and in that form I have a drop list and I would like to create a report to the from the reference I selected.

Currently when I select the reference item it will pull up all forms with the reference that is selected (This works Great.
What I would like to do is take this to another level. Instead of it opening the form I would like it to open a report. I tried removing "frmShipping" and replacing it with "rptShipping" but I keeping on getting an error. I created a report named rptShipping which is based on a query.

I here is the code I used to open the forms.


Private Sub ReferenceLookup_AfterUpdate()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmShipping"

stLinkCriteria = "[Reference]=" & "'" & Me![ReferenceLookup] & "'"
DoCmd.Close acForm, "frmReferenceLookUp", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub


This is still new to me so be gentle.:eek:
Thanks
Art
 
What's the code you tried that failed? You would have to change

DoCmd.OpenForm...

to

DoCmd.OpenReport...
 
This is the current code:
Private Sub ReferenceLookup_AfterUpdate()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmShipping"

stLinkCriteria = "[Reference]=" & "'" & Me![ReferenceLookup] & "'"
DoCmd.Close acForm, "frmReferenceLookUp", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub



This is the one that failed:

Private Sub ReferenceLookup_AfterUpdate()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptReferenceReport"

stLinkCriteria = "[Reference]=" & "'" & Me![ReferenceLookup] & "'"
DoCmd.Close acForm, "frmReferenceLookUp", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
 
Then it appears I've already answered the question...
 
I should have read it more carefully. So simple I will try that.
 
Changed the code and it worked. But I have a question. When I select the Reference and it creates the report it goes straight to the printer. I would like to preview the form.

Private Sub ReferenceLookup_AfterUpdate()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptReferenceReport"

stLinkCriteria = "[Reference]=" & "'" & Me![ReferenceLookup] & "'"
DoCmd.Close acForm, "frmReferenceLookUp", acSaveNo
DoCmd.OpenReport stDocName, , , stLinkCriteria
End Sub
 
If you looked at Help for OpenReport, you'd see the argument that controlled that:

DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

The default is straight to the printer, which is why it does that when you leave the argument blank.
 
Yes I did see that in the help. But did not know where to insert or create a new event. But know I know I should insert.
 

Users who are viewing this thread

Back
Top Bottom