Having problems printing a single report

F

forest8

Hi

This is the code I have entered in the event procedure to print a single
record.

Unfortunately, it's not working. How do I fix this code:

Private Sub Print_this_record_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "R1-1 GPS_GeneralInfo"
strWhere = "[StudentID]=" & Me!StudentID
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub


I need to print out one StudentID for the report R1-1 GPS_GeneralInfo. When
I click on the button, a popup box with the Student CG2002 appears.

Thanks for your help in advance.
 
A

Allen Browne

It seems your student code field is a text field, not a number field. You
will therefore need to add quotes:
strWhere = "[StudentID]=""" & Me!StudentID & """"

For an explanation of the quotes, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html
 
F

forest8

Should I be using the primary key or can I use any variable?

Thank you.


Allen Browne said:
It seems your student code field is a text field, not a number field. You
will therefore need to add quotes:
strWhere = "[StudentID]=""" & Me!StudentID & """"

For an explanation of the quotes, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


forest8 said:
Hi

This is the code I have entered in the event procedure to print a single
record.

Unfortunately, it's not working. How do I fix this code:

Private Sub Print_this_record_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "R1-1 GPS_GeneralInfo"
strWhere = "[StudentID]=" & Me!StudentID
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub


I need to print out one StudentID for the report R1-1 GPS_GeneralInfo.
When
I click on the button, a popup box with the Student CG2002 appears.

Thanks for your help in advance.

.
 
D

Duane Hookom

Whatever value you use should be unique. This is generally a primary key
field/value.

--
Duane Hookom
MS Access MVP


forest8 said:
Should I be using the primary key or can I use any variable?

Thank you.


Allen Browne said:
It seems your student code field is a text field, not a number field. You
will therefore need to add quotes:
strWhere = "[StudentID]=""" & Me!StudentID & """"

For an explanation of the quotes, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


forest8 said:
Hi

This is the code I have entered in the event procedure to print a
single
record.

Unfortunately, it's not working. How do I fix this code:

Private Sub Print_this_record_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "R1-1 GPS_GeneralInfo"
strWhere = "[StudentID]=" & Me!StudentID
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub


I need to print out one StudentID for the report R1-1 GPS_GeneralInfo.
When
I click on the button, a popup box with the Student CG2002 appears.

Thanks for your help in advance.

.
 

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