Print multiple reports

R

Renee

I have created a button on my employee info form to print about 6-8 reports
based on the employee number and have used this code for the on click event:

Private Sub PRINT_DOCS_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[EMPLOYEE NUMBER] = " & Me.[EMPLOYEE NUMBER]
DoCmd.OpenReport "AHC", acViewPreview, , strWhere
DoCmd.OpenReport "QUICKCARD", acViewPreview, , strWhere
End If

End Sub

When I click on the button it gives me a run time error '2465': access can't
find the field 'l' referred to in your expression. I am not sure what this
error is refurring to and when I go to the debug and highlights this line of
my expression:

strWhere = "[EMPLOYEE NUMBER] = " & Me.[EMPLOYEE NUMBER]

Can anyone clear this up for me?
Thank you.
 
A

Allen Browne

Do you have a text box named :
Employee Number
on your form?
With the space?

Does the code compile?
(Compile on Debug menu, in code window?)
 
R

Renee

Yes, I do have a text box called Employee Number, but its not on the main
form its on a subform.

And I am not sure what you mean by the code compile

Allen Browne said:
Do you have a text box named :
Employee Number
on your form?
With the space?

Does the code compile?
(Compile on Debug menu, in code window?)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Renee said:
I have created a button on my employee info form to print about 6-8 reports
based on the employee number and have used this code for the on click
event:

Private Sub PRINT_DOCS_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[EMPLOYEE NUMBER] = " & Me.[EMPLOYEE NUMBER]
DoCmd.OpenReport "AHC", acViewPreview, , strWhere
DoCmd.OpenReport "QUICKCARD", acViewPreview, , strWhere
End If

End Sub

When I click on the button it gives me a run time error '2465': access
can't
find the field 'l' referred to in your expression. I am not sure what this
error is refurring to and when I go to the debug and highlights this line
of
my expression:

strWhere = "[EMPLOYEE NUMBER] = " & Me.[EMPLOYEE NUMBER]

Can anyone clear this up for me?
Thank you.
 
R

Renee

When I open the code and click on the debug menu the complie is not there,
its greyed out.

Allen Browne said:
Do you have a text box named :
Employee Number
on your form?
With the space?

Does the code compile?
(Compile on Debug menu, in code window?)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Renee said:
I have created a button on my employee info form to print about 6-8 reports
based on the employee number and have used this code for the on click
event:

Private Sub PRINT_DOCS_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[EMPLOYEE NUMBER] = " & Me.[EMPLOYEE NUMBER]
DoCmd.OpenReport "AHC", acViewPreview, , strWhere
DoCmd.OpenReport "QUICKCARD", acViewPreview, , strWhere
End If

End Sub

When I click on the button it gives me a run time error '2465': access
can't
find the field 'l' referred to in your expression. I am not sure what this
error is refurring to and when I go to the debug and highlights this line
of
my expression:

strWhere = "[EMPLOYEE NUMBER] = " & Me.[EMPLOYEE NUMBER]

Can anyone clear this up for me?
Thank you.
 
R

Renee

Ok, still gave me the same error, but looking at my form again the form where
the field employee number is is a subform of a subform on the main form. So
do I have to add the other subform name to my code as well?

Allen Browne said:
If it's in the subform, you will need to refer to it as:
Me.[Sub1].Form![Employee Number]
using the name of your subform control in place of Sub1.

Explanation:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Renee said:
Yes, I do have a text box called Employee Number, but its not on the main
form its on a subform.
 
A

Allen Browne

You need to review that article, and understand what you are doing, not
merely expect us to do it for you.

The expression will be of the form:
Me.[Sub1].Form![Sub2].Form![Employee Number]

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Renee said:
Ok, still gave me the same error, but looking at my form again the form
where
the field employee number is is a subform of a subform on the main form.
So
do I have to add the other subform name to my code as well?

Allen Browne said:
If it's in the subform, you will need to refer to it as:
Me.[Sub1].Form![Employee Number]
using the name of your subform control in place of Sub1.

Explanation:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

Renee said:
Yes, I do have a text box called Employee Number, but its not on the
main
form its on a subform.

Do you have a text box named :
Employee Number
on your form?
 

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