Having problems printing a single report

  • Thread starter Thread starter forest8
  • Start date Start date
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.
 
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
 
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.

.
 
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.

.
 
Back
Top