Command Button to Print referring to two fields

PattyS

Registered User.
Local time
Today, 13:56
Joined
Jun 20, 2006
Messages
39
can you have a code behind a command button to print a record with refference to two fields
example:
field> LastName = Smith
field>Date= 05-01-11

now because mr smith has several orders and they are differentiated
by the date that he made each order (on a subform)

I have created a Report to print out the items ordered
I put a command button on the bottom of the order form

Private Sub Print Form_Click()
Dim strWhere As String
strWhere = "LastName='" & Me.LastName & "'"
DoCmd.OpenReport "ORDER", acViewNoemal, , strWhere
End Sub

this code prints the report with Mr smith but also prints all and every record that has mr smith name

if the code above could be changed to ONLY PRINT the current record being viewed or somehow connect the name with the date

I dont know, I am just looking for an easy fix
ps > had posted simular questions with no answers
just let me know if this can be done
and if so
then could you help with the code
 
I would expect there to be a key field to be used instead of name/date, but this type of thing should work:

strWhere = "LastName='" & Me.LastName & "' AND DateField = #" & Me.DateField & "#"
 
I will be keeping my fingers crossed that is all that simple
I will apply it at work tomorrow
thanks
 
ok, having a YELLOW line issue
this is yours

strWhere = "LastName='" & Me.LastName & "' AND DateField = #" & Me.DateField & "#"
not sure about the colons and pernthises ' " or " '

ran and this error came up
runtime erroe 3075
syntax error in string in query expression
'LastName='100-SMITH AND DateField=#042811#'
and then
debugged this line is in yellow
DoCmd.OpenReport "ORDERS", acViewPreview,,strWhere

be advised that thr DateField is formatted text @@\/@@\/@@
 
Not sure why you'd have a date field as text, but try

strWhere = "LastName='" & Me.LastName & "' AND DateField = '" & Me.DateField & "'"
 

Users who are viewing this thread

Back
Top Bottom