Open A Report from a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Below is the code I am currently using to open a Report from a Form. I want
to know how I can use additional criteria. I want it to not only look at
CO_Number, but I want it to Match CO_LN_NO as well. Both of those fields
reside in the form, and both fields are in the same source table as CO_Number.

Thanks Tony

Public Function Serialization()
On Error GoTo Err_Command306_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = IIf([Cust_ID] = "07P071", "Premier Serialization",
IIf([Cust_ID] = "03F001", "Fulton Serialization", IIf([Cust_ID] Like "10*",
"Hicksgas Serialization", IIf([Cust_ID] = "07M021", "Myers Serialization",
"Marlo Serialization"))))

stLinkCriteria = "[CO_NUMBER]=" & "'" & Me![CO_NUMBER] & "'"
DoCmd.OpenReport stDocName, , , stLinkCriteria

Exit_Command306_Click:
Exit Function

Err_Command306_Click:
MsgBox Err.Description
Resume Exit_Command306_Click
 
Below is the code I am currently using to open a Report from a Form. I want
to know how I can use additional criteria. I want it to not only look at
CO_Number, but I want it to Match CO_LN_NO as well. Both of those fields
reside in the form, and both fields are in the same source table as CO_Number.

Thanks Tony

Public Function Serialization()
On Error GoTo Err_Command306_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = IIf([Cust_ID] = "07P071", "Premier Serialization",
IIf([Cust_ID] = "03F001", "Fulton Serialization", IIf([Cust_ID] Like "10*",
"Hicksgas Serialization", IIf([Cust_ID] = "07M021", "Myers Serialization",
"Marlo Serialization"))))

stLinkCriteria = "[CO_NUMBER]=" & "'" & Me![CO_NUMBER] & "'"
DoCmd.OpenReport stDocName, , , stLinkCriteria

Exit_Command306_Click:
Exit Function

Err_Command306_Click:
MsgBox Err.Description
Resume Exit_Command306_Click

As written, your [Co_Number] field is Text datatype.
Is that correct? If so, is the [CO_LN_NO] field also Text datatype?

Assuming both criteria fields are text datatype:

stLinkCriteria = "[CO_NUMBER]= '" & Me![CO_NUMBER] & "' And
[CO_LN_NO] = '" & Me![C0_LN_NO] & "'"

Notice that I have changed the quotes from what you had written.

In VBA help look up
Where clasue + Restrict data to a subset of records
for how to write the where clause for the different datatypes.
 
Back
Top