report on current record

B

BLTibbs

I am trying to print the current record from a form using the following code
and the report allways comes up with #error in the field names. What did I
do wrong?

'print single label record from form
Dim strWhere As String
Dim stDocName As String
If Me.Dirty Then
Me.Dirty = False
End If
stDocName = "ShipLabelRpt"
strWhere = "[order-id] = '" & Form_CustomerServiceFrm.order_id & "'"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
 
T

tina

does the report show the data correctly if you open it manually from the
database window?

hth
 
F

fredg

I am trying to print the current record from a form using the following code
and the report allways comes up with #error in the field names. What did I
do wrong?

'print single label record from form
Dim strWhere As String
Dim stDocName As String
If Me.Dirty Then
Me.Dirty = False
End If
stDocName = "ShipLabelRpt"
strWhere = "[order-id] = '" & Form_CustomerServiceFrm.order_id & "'"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere

Is this code located on the Form_CustomerServiceFrm form?
What is the datatype of [Order_ID]?
If it is Number datatype, then use:
strWhere = "[order-id] = " & Me![order_id]

If it is Text datatype, then:
strWhere = "[order-id] = '" & Me![order_id] & "'"

If thise code is NOT on the Form_CustomerServiceFrm form, then you
must use the full forms collection syntax:
strWhere = "[order-id] = '" & forms!Form_CustomerServiceFrm![order_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