strLinkCriteria not working properly

G

Guest

Can anyone tell me what I am doing wrong here.

I am trying to open a report via a command button on a form. But when I
click on the command button I get the "Enter Parameter Value" text box asking
for a value for Me!Rental_FK_Job_ID. If I enter the value it the correct
form appears but I want it to automatically open. I don't want my user to
have to enter the value.

Here is my code.

Private Sub Btn_PrvwRental_Bill_Sht_Click()
On Error GoTo Err_Btn_PrvwRental_Bill_Sht_Click

Dim stDocName As String, strLinkCriteria As String

stDocName = "frm_Rental_Billing_Sheet"
strLinkCriteria = "[Job_ID] = Me![Rental_FK_Job_ID]"

DoCmd.OpenReport stDocName, acPreview, , strLinkCriteria

Exit_Btn_PrvwRental_Bill_Sht_Click:
Exit Sub

Err_Btn_PrvwRental_Bill_Sht_Click:
MsgBox Err.Description
Resume Exit_Btn_PrvwRental_Bill_Sht_Click

End Sub

Thank you,
 
F

fredg

Can anyone tell me what I am doing wrong here.

I am trying to open a report via a command button on a form. But when I
click on the command button I get the "Enter Parameter Value" text box asking
for a value for Me!Rental_FK_Job_ID. If I enter the value it the correct
form appears but I want it to automatically open. I don't want my user to
have to enter the value.

Here is my code.

Private Sub Btn_PrvwRental_Bill_Sht_Click()
On Error GoTo Err_Btn_PrvwRental_Bill_Sht_Click

Dim stDocName As String, strLinkCriteria As String

stDocName = "frm_Rental_Billing_Sheet"
strLinkCriteria = "[Job_ID] = Me![Rental_FK_Job_ID]"

DoCmd.OpenReport stDocName, acPreview, , strLinkCriteria

Exit_Btn_PrvwRental_Bill_Sht_Click:
Exit Sub

Err_Btn_PrvwRental_Bill_Sht_Click:
MsgBox Err.Description
Resume Exit_Btn_PrvwRental_Bill_Sht_Click

End Sub

Thank you,

You need to concatenate the value into the expression, otherwise
Access looks for a literal "Rental_FK_Job_ID".

Assuming [Rental_FK_Job_ID] is a Number datatype,
try:

strLinkCriteria = "[Job_ID] = " & Me![Rental_FK_Job_ID]
 
G

Guest

Thank you so much. I knew it had to do with the quotations but I just could
not figure it out.



fredg said:
Can anyone tell me what I am doing wrong here.

I am trying to open a report via a command button on a form. But when I
click on the command button I get the "Enter Parameter Value" text box asking
for a value for Me!Rental_FK_Job_ID. If I enter the value it the correct
form appears but I want it to automatically open. I don't want my user to
have to enter the value.

Here is my code.

Private Sub Btn_PrvwRental_Bill_Sht_Click()
On Error GoTo Err_Btn_PrvwRental_Bill_Sht_Click

Dim stDocName As String, strLinkCriteria As String

stDocName = "frm_Rental_Billing_Sheet"
strLinkCriteria = "[Job_ID] = Me![Rental_FK_Job_ID]"

DoCmd.OpenReport stDocName, acPreview, , strLinkCriteria

Exit_Btn_PrvwRental_Bill_Sht_Click:
Exit Sub

Err_Btn_PrvwRental_Bill_Sht_Click:
MsgBox Err.Description
Resume Exit_Btn_PrvwRental_Bill_Sht_Click

End Sub

Thank you,

You need to concatenate the value into the expression, otherwise
Access looks for a literal "Rental_FK_Job_ID".

Assuming [Rental_FK_Job_ID] is a Number datatype,
try:

strLinkCriteria = "[Job_ID] = " & Me![Rental_FK_Job_ID]
 

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