Help with code

  • Thread starter Thread starter A Moloney
  • Start date Start date
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
 
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] & "#"
 
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.
.
 
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.
 
Back
Top