Preview Print Report

G

Guest

I have set up an eventprocedure with the following code to preview a report
from my form screen. I've got it to open the report in preview mode but I
want it to filter to the record that I'm on. The problem is that I have two
identifiers "CRSE_CD" and "SESSION_NO" which are both text fields. How do I
implement this filter into my event procedure coding?


Private Sub PackingList_Click()
On Error GoTo Err_PackingList_Click
DoCmd.OpenReport "RptPackingList", acViewPreview

Exit_PackingList_Click:
Exit Sub

Err_PackingList_Click:
MsgBox Err.Description
Resume Exit_PackingList_Click
End Sub
 
A

Albert D.Kallal

The following code should work.

Private Sub PackingList_Click()

dim strWhere as string

me.Refresh ' need to write data to disk, else
' report will not see the data!!

strWhere = "CRSE_CD = '" & me!CURSE_CD & "'" _
" and SESSION_NO = '" & me!SESSION_NO & "'"


On Error GoTo Err_PackingList_Click
DoCmd.OpenReport "RptPackingList", acViewPreview,,strWhere

Exit_PackingList_Click:
Exit Sub

Err_PackingList_Click:
MsgBox Err.Description
Resume Exit_PackingList_Click
End Sub
 
G

Guest

Thanks for the info. Unfortunately I get an error sign that says: Compile
Error: Syntax Error

What do I do now? Question: this code may work in Access 2003 but I am
working in Access 2002. Is the code different then?
 
D

Douglas J. Steele

Albert's code should work in earlier versions as well.

Copy and paste exactly what you've got into your reply and maybe someone
will see your error.
 
G

Guest

This is the code I have in visualbasic:
Private Sub PackingList_Click()

Dim strWhere As String

Me.Refresh
strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" _
" and SESSION_NO = '" & Me!SESSION_NO & "'"



On Error GoTo Err_PackingList_Click
DoCmd.OpenReport "RptPackingList", acViewPreview, , strWhere

Exit_PackingList_Click:
Exit Sub

Err_PackingList_Click:
MsgBox Err.Description
Resume Exit_PackingList_Click
End Sub

The error message says: Compile Error: Expected: End of statement . I don't
know if this helps.
 
A

Albert D.Kallal

strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" _
" and SESSION_NO = '" & Me!SESSION_NO & "'"

opps...we are mssing a & sign....try

strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" _
& " and SESSION_NO = '" & Me!SESSION_NO & "'"

We could just put the whole thing on one line..but the newsreader tends to
wrap it...

strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" & " and SESSION_NO = '" &
Me!SESSION_NO & "'"

And, as a last check, the report is bound to a table, or query that has a
field called CRSE_CD, and also
SESSION_NO....right?

Anway, I missed the & sign....sorry....
 
G

Guest

Thanks Albert, the underscore in the first line right before the & sign
brings up an error that says "invalid character" if I just delete this
underscore, it opens the report but none of the fields are populated on the
report. I appreciate your help thus far.
 
C

Carter

you could always use those criteria in a query and then use that as the
source for your report.
 
A

Albert D.Kallal

Thanks Albert, the underscore in the first line right before the & sign
brings up an error that says "invalid character" if I just delete this
underscore, it opens the report but none of the fields are populated on
the
report. I appreciate your help thus far.

The follwign should be ok

strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" _
& " and SESSION_NO = '" & Me!SESSION_NO & "'"

or

strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" & _
" and SESSION_NO = '" & Me!SESSION_NO & "'"

Either one should work just fine...

Well, lets just put the whole thing on one line...

strWhere = "CRSE_CD = '" & Me!CRSE_CD & "'" & " and SESSION_NO = '" &
Me!SESSION_NO & "'"

there should be no wrap (the news reader is doing that) as above..but just
place the whole thing on one line....

For testing, put right after the above, put

debug.print strWhere

You can then run the code, and when you open the debug window, you can see
the "where" text.....is it ok?

(you can even cut and paste that strWhere into your next message for all of
us to view).....

So, run it...and then open up the debug window, and we can all take a look
at what strWhere has inside of it...
 

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

Similar Threads


Top