Help with code

A

A Moloney

Hi
I have a command button that prints a report when clicked
and has the following code;

Private Sub Print10a_Click()
On Error GoTo Err_Print10a_Click
Dim strWhere As String
Dim stDocName As String
strWhere = "Date=" & Me.Date

stDocName = "10aConfirmation"
DoCmd.OpenReport stDocName, acNormal, , strWhere
DoCmd.OpenReport stDocName, acNormal, , strWhere


Exit_Print10a_Click:
Exit Sub

Err_Print10a_Click:
MsgBox Err.Description
Resume Exit_Print10a_Click

End Sub

The problem that i have is that it prints two copies of
the report (which i want) but does not include the
information that is detailed on the table, it prints
blank fields. can anyone see a problem with the above
code (apart from the fact that i have a field
called ''Date'' (Access recognises this field for all
other functions/macros anyway)
Any help arreciated
 
F

fredg

Hi
I have a command button that prints a report when clicked
and has the following code;

Private Sub Print10a_Click()
On Error GoTo Err_Print10a_Click
Dim strWhere As String
Dim stDocName As String
strWhere = "Date=" & Me.Date

stDocName = "10aConfirmation"
DoCmd.OpenReport stDocName, acNormal, , strWhere
DoCmd.OpenReport stDocName, acNormal, , strWhere

Exit_Print10a_Click:
Exit Sub

Err_Print10a_Click:
MsgBox Err.Description
Resume Exit_Print10a_Click

End Sub

The problem that i have is that it prints two copies of
the report (which i want) but does not include the
information that is detailed on the table, it prints
blank fields. can anyone see a problem with the above
code (apart from the fact that i have a field
called ''Date'' (Access recognises this field for all
other functions/macros anyway)
Any help arreciated

The fact that Access has until now recognized [Date] as a field name
and operated OK is no guarantee that it is recognizing [Date] as a
field now and not as the Date() function.
Using any reserved word is a risky business. That's why they are
reserved.

1) Change the field name.

2) Surround it with brackets and the date indicator symbol:
strWhere = "[DateField] = #" & Me![DateControl] & "#"
 
A

A Moloney

Thanks Fred, 2 questions though (sorry - quite new to
access)
1) what do i enter in the code for the date control? I
added Calendar1 (as i have a calendar on my form) but teh
code brings up a enter parameter box headed dateField;
what would users enter into this?
-----Original Message-----
Hi
I have a command button that prints a report when clicked
and has the following code;

Private Sub Print10a_Click()
On Error GoTo Err_Print10a_Click
Dim strWhere As String
Dim stDocName As String
strWhere = "Date=" & Me.Date

stDocName = "10aConfirmation"
DoCmd.OpenReport stDocName, acNormal, , strWhere
DoCmd.OpenReport stDocName, acNormal, , strWhere

Exit_Print10a_Click:
Exit Sub

Err_Print10a_Click:
MsgBox Err.Description
Resume Exit_Print10a_Click

End Sub

The problem that i have is that it prints two copies of
the report (which i want) but does not include the
information that is detailed on the table, it prints
blank fields. can anyone see a problem with the above
code (apart from the fact that i have a field
called ''Date'' (Access recognises this field for all
other functions/macros anyway)
Any help arreciated

The fact that Access has until now recognized [Date] as a field name
and operated OK is no guarantee that it is recognizing [Date] as a
field now and not as the Date() function.
Using any reserved word is a risky business. That's why they are
reserved.

1) Change the field name.

2) Surround it with brackets and the date indicator symbol:
strWhere = "[DateField] = #" & Me![DateControl] & "#"


--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
 
F

fredg

Thanks Fred, 2 questions though (sorry - quite new to
access)
1) what do i enter in the code for the date control? I
added Calendar1 (as i have a calendar on my form) but teh
code brings up a enter parameter box headed dateField;
what would users enter into this? *** snipped ***
The fact that Access has until now recognized [Date] as a field name
and operated OK is no guarantee that it is recognizing [Date] as a
field now and not as the Date() function.
Using any reserved word is a risky business. That's why they are
reserved.

1) Change the field name.

2) Surround it with brackets and the date indicator symbol:
strWhere = "[DateField] = #" & Me![DateControl] & "#"


--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.

I didn't mean for you to add the calendar control.
My
Me![DateControl]
referred to the actual name of the text control on your form that
shows the date wanted. I have no idea what it's named, but whatever it
is named, that's the name you substitute for [DateControl].
If the control is already named "Date" change that to something else.

[DateField] refers to what ever you have renamed the [Date] field to.
You have renamed that field, haven't you?
Substitute the newly named field name.

So, if you renamed [Date] to [TheDate] and the control on the Form is
named Text20, then:
strWhere = "[TheDate] #" & Me![Text20] & "#"

That's only one question. I don't see another.

By the way, after you change the name of the field, you'll have to go
through all your reports forms, queries, etc. and make sure that the
field name is changed there also.
 

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

Similar Threads

Tidying my report 2
Adding control to report 1
Report code 2
Filtering a report by controls 4
Use combo to print report between two sets of dates 1
Changing Header Label 1
Help!! 3
Subreport - current year 1

Top