Open Report

G

Guest

I use the following code to open a specific report...

Private Sub BoxID_Click()
DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" & Me.BoxNumber
End Sub

I need to add a component to the Where clause and am unsure how to word it.
I need to add that the TestVer = SDAA. I only need to see the tests that are
type SDAA. I don't need the others. What is the wording for adding a
stipulation like that?
 
G

Guest

DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" &
Me.BoxNumber & " AND TestVer = 'SDAA'"
 
G

Guest

1 More question. I have 2 versions of the test that I need to include. To
include the TestVersion, in the field called TestVer, to the Where condition
instead of actually typing it in I tried using:

Private Sub BoxID_Click()
DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" &
Me.BoxNumber And "Test=" & Me.TestVer
End Sub

But I get an debug error on the Test= & Me.TestVer portion. When I
mouseover the Me.TestVer it tells me the correct name, but it still won't
open. Do I have an error in syntax because it is a text field?
 
F

fredg

1 More question. I have 2 versions of the test that I need to include. To
include the TestVersion, in the field called TestVer, to the Where condition
instead of actually typing it in I tried using:

Private Sub BoxID_Click()
DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" &
Me.BoxNumber And "Test=" & Me.TestVer
End Sub

But I get an debug error on the Test= & Me.TestVer portion. When I
mouseover the Me.TestVer it tells me the correct name, but it still won't
open. Do I have an error in syntax because it is a text field?

You didn't follow David's coding.

Your code of

DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" &
Me.BoxNumber And "Test=" & Me.TestVer

is not written the same as David's

DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" &
Me.BoxNumber & " AND TestVer = 'SDAA'"

1) You neglected to include the & after Me.BoxNumber.
2) You neglected to place the double quote before the word And.
3) A Text datatype value must be enclosed within single or double
quotes. Because you are already using double quotes in the Where
clause, you must use single quotes around the Text datatype variable.
You neglected to place the single quotes around Me.TestVer.

Try:
DoCmd.OpenReport "rptBoxPrintout", acViewNormal, , "BoxNumber=" &
Me.BoxNumber & " AND TestVer = '" & Me.TestVer & "'"

I would suggest you look up, in VBA help:
Where clause + Restrict data to a subset of records
 
G

Guest

And "Test='" & Me.TestVer & "'"
Text fields must be enclosed in single or double qoutes
 

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