Print Report of Current Record Shown on Form

B

Bob Loder

Hi, Friends,

This was discussed several days ago, and I was pleasantly amazed, because it
was exactly my latest challenge!

I have a form that shows a lot of info on a record by record basis - nothing
glamourous, no subforms - pretty straight forward.

I want to be able to print a "version" of a pre-defined report
(rptWorkInProgress) which works fine by itself when it displays all records
(don't panic, there are only 63 records), but it doesn't like my command
button to print just the current record in report using that report.

I "plagarized" code being discussed on the topic over the weekend, but
actually, the topical issue was never resolved. Still getting error:

===========================================
Run-time error '3075':
Syntax error (missing operator) in query expression
'([Insured]=Devonshire)'.
===========================================

-or-
if name has a comma (Smith, John):

===========================================
Run-time error '3075':
Syntax error (comma) in query expression '([Insured]=Smith, John)'.
===========================================

My code in On Click for command button on Form (as plagarized, and altered
from previous discussion!) is as follows:

=============================================
Private Sub PrintThisRecordFull_Click()

Dim strWhere As String
If Me.Dirty Then 'Save any changes.
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select A Record To Print"
Else
strWhere = "[Insured]=" & Me.[Insured]
DoCmd.OpenReport "rptFullWorkInProgress", acViewPreview, , strWhere
End If

End Sub
==============================================
Debug points me to DoCmd.OpenReport . . . line

Maybe because report calls up all records in Db, not filtered, or locked, or
.. . . ? Similar to original writer, if I invoke command from a blank data
entry screen, I get a predictable "Select A Record To Print".

Ya know, this all seemed easy (report on current record) before I started!

Thanks in advance,
Bob Loder
Tampa, FL
 
B

Bob Loder

Report name in third paragraph in error. It is correctly identified in code
as rptFullWorkInProgress
 
J

Joan Wild

Hi Bob,

It's because the [Insured] field is text. You need to surround the value in
quotes.
Change your strWhere line to

strWhere = "[Insured]= " & chr(34) & Me.[Insured] & chr(34)
 
B

Bob in Tampa

Hi, Joan,

Yes!!! Thank You - Thank You - Thank You <( ; - )

New Question:
Recommended reading to learn **and understand** vba code. A book that not
only says do this - or use this - but also explains what different "code
words" mean. For example "Dim" or "Wend" - I have a vague idea how to use
them, but what are these words? I learn much better from understanding than
simply rote memory. Obviously I am a new student of the Access game!

These "microsoft.public.access.*" newsgroups are incredible! What a super
group of knowledgeable and **patient** folks. I look forward to the day
when I can give as well as receive.

Thanks again.

Bob Loder
Tampa, FL
 
C

Chris

Book recommendations: Access Developer's Handbook by Ken
Getz.

It might be above your current level, but it is a must for
every Access developer. I use mine all the time.

Other Books:

Look into Visual Basic 6.0 books. The difference isn't
that great, other than VB uses alot more unbound controls,
data controls, and harder reporting. But the VB syntax is
the same, and will help you get up and running.


Chris
 
B

Bob Loder

Thanks, Chris!

Access Developer's Handbook by Ken Getz will be mine tomorrow!

Bob Loder
Tampa, FL
 
J

Joan Wild

Bob in Tampa said:
Hi, Joan,

Yes!!! Thank You - Thank You - Thank You <( ; - )

Glad it worked for you.
New Question:
Recommended reading to learn **and understand** vba code. A book that not
only says do this - or use this - but also explains what different "code
words" mean. For example "Dim" or "Wend" - I have a vague idea how to use
them, but what are these words? I learn much better from understanding than
simply rote memory. Obviously I am a new student of the Access game!

I'd suggest
Beginning Access xxx(ver) VBA by Smith & Sussman - Wrox Press
Access Database Design & Programming by Roman - O'Reilly Press

to start and eventually you'll find the Developer's Handbook as recommended
by Chris indispensible.
 

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