Open Report with criteria in VBA

G

Guest

Hey guys,
here is the deal. I am opening a report from a form (tab control type of
form) that has a combo box with a list of Airport codes (station).
here is the code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim stValue As String

stDocName = "rpt_StnRecord"
stValue = Me![Combo12]
stLinkCriteria = "[Station]=" & stValue
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

As you can see, the report (rpt_StnRecord) is supposed to open using as
Station (field) criteria the value in the Combo12 (located on the tab form).
This works well except that I cannot get the report to open right away. I get
another box popping up asking me to enter the station value (which is already
in combo12).

I dont get it. Any idea?
Thanks guys.
Alec
 
E

Eric D via AccessMonster.com

Change the Me![Combo12] to Forms![YourFormName].[Combo12]

I believe that because you are using Me![Combo12] and opening a report, the
report gets the focus and looks for Me![Combo12]... which it can't find.
Bottom line... never use Me![FieldName] when passing variables.
Hey guys,
here is the deal. I am opening a report from a form (tab control type of
form) that has a combo box with a list of Airport codes (station).
here is the code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim stValue As String

stDocName = "rpt_StnRecord"
stValue = Me![Combo12]
stLinkCriteria = "[Station]=" & stValue
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

As you can see, the report (rpt_StnRecord) is supposed to open using as
Station (field) criteria the value in the Combo12 (located on the tab form).
This works well except that I cannot get the report to open right away. I get
another box popping up asking me to enter the station value (which is already
in combo12).

I dont get it. Any idea?
Thanks guys.
Alec
 
G

Guest

I just tried and it does not work. I still a little pop up window where I
have to enter the value.
Any other suggestions?
Thanks for your help.

Eric D via AccessMonster.com said:
Change the Me![Combo12] to Forms![YourFormName].[Combo12]

I believe that because you are using Me![Combo12] and opening a report, the
report gets the focus and looks for Me![Combo12]... which it can't find.
Bottom line... never use Me![FieldName] when passing variables.
Hey guys,
here is the deal. I am opening a report from a form (tab control type of
form) that has a combo box with a list of Airport codes (station).
here is the code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim stValue As String

stDocName = "rpt_StnRecord"
stValue = Me![Combo12]
stLinkCriteria = "[Station]=" & stValue
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

As you can see, the report (rpt_StnRecord) is supposed to open using as
Station (field) criteria the value in the Combo12 (located on the tab form).
This works well except that I cannot get the report to open right away. I get
another box popping up asking me to enter the station value (which is already
in combo12).

I dont get it. Any idea?
Thanks guys.
Alec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top