Printing single record

G

Guest

HELP!

I am using the following code under the ComandButton to print the current
report from my form:

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 = "[Num] = " & Me.[Num]
DoCmd.OpenReport "Check Request", acViewNormal, , strWhere
End If

However, I keep getting the following error:

The expression On Click you entered as the event property setting produced
the following error: Object or class does not support the set of events.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

The first day I used it, it worked, but for some reason unknown to me, it
stop working. I haven’t made any changes. I’ve even tried recreating the
function, but still no luck. Would really appreciate some assistance.
Thanks.
 
G

Guest

Ellie said:
HELP!

I am using the following code under the ComandButton to print the current
report from my form:

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 = "[Num] = " & Me.[Num]
DoCmd.OpenReport "Check Request", acViewNormal, , strWhere
End If

However, I keep getting the following error:

The expression On Click you entered as the event property setting produced
the following error: Object or class does not support the set of events.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

The first day I used it, it worked, but for some reason unknown to me, it
stop working. I haven’t made any changes. I’ve even tried recreating the
function, but still no luck. Would really appreciate some assistance.
Thanks.
Hi Ellie
One thing is not clear. Is the report based on a Query?
If it is and you want just to print the current records then I think you
should create a filter.

Example
Create a new query ie qryFilter
Use the the query which your report is based on and project the asteric * in
to the
new query first Column so that all fields are selected.
Hoping Num is the primary key in the second column project Num and in the
criteria area specify [Forms]![Formname]![txtNum]
Close this query and return to your form.
On the CommandButton click event enter this code

Dim stDocName as String
Dim strFilter as String

strFilter = "qryFilter"
stDocName ="Check Request"
DoCmd.OpenReport stDocName, acViewNormal, strFilter

I advise you look at the Northwind orders form in design view and see the
code behind the print invoice Command Button
 
G

Guest

The code looks fine, and the error suggests that its not the code that's the
problem. What appears in the button's property sheet as the On Click event
property?

If, as is more likely, the code is in the button's Click event procedure
then it should say [Event Procedure] in the properties sheet. If on the
other hand the code is in a separate function you've created in the form's
module then the On Click event property should be the name of the function
preceded by an = sign and followed by parentheses:

=YourFunctionName()

Ken Sheridan
Stafford, England
 
G

Guest

The code is in the button's On Click event--[Event Procedure]. This is
really wierd, because it worked the first day. Thanks.


Ken Sheridan said:
The code looks fine, and the error suggests that its not the code that's the
problem. What appears in the button's property sheet as the On Click event
property?

If, as is more likely, the code is in the button's Click event procedure
then it should say [Event Procedure] in the properties sheet. If on the
other hand the code is in a separate function you've created in the form's
module then the On Click event property should be the name of the function
preceded by an = sign and followed by parentheses:

=YourFunctionName()

Ken Sheridan
Stafford, England

Ellie said:
HELP!

I am using the following code under the ComandButton to print the current
report from my form:

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 = "[Num] = " & Me.[Num]
DoCmd.OpenReport "Check Request", acViewNormal, , strWhere
End If

However, I keep getting the following error:

The expression On Click you entered as the event property setting produced
the following error: Object or class does not support the set of events.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

The first day I used it, it worked, but for some reason unknown to me, it
stop working. I haven’t made any changes. I’ve even tried recreating the
function, but still no luck. Would really appreciate some assistance.
Thanks.
 
G

Guest

My report is not based on a query, but on a Form. Based on your
instructions, will I need to recreate the form? That I would rather not do
because this form is a custom made form. Thanks.

Muriukis said:
Ellie said:
HELP!

I am using the following code under the ComandButton to print the current
report from my form:

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 = "[Num] = " & Me.[Num]
DoCmd.OpenReport "Check Request", acViewNormal, , strWhere
End If

However, I keep getting the following error:

The expression On Click you entered as the event property setting produced
the following error: Object or class does not support the set of events.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

The first day I used it, it worked, but for some reason unknown to me, it
stop working. I haven’t made any changes. I’ve even tried recreating the
function, but still no luck. Would really appreciate some assistance.
Thanks.
Hi Ellie
One thing is not clear. Is the report based on a Query?
If it is and you want just to print the current records then I think you
should create a filter.

Example
Create a new query ie qryFilter
Use the the query which your report is based on and project the asteric * in
to the
new query first Column so that all fields are selected.
Hoping Num is the primary key in the second column project Num and in the
criteria area specify [Forms]![Formname]![txtNum]
Close this query and return to your form.
On the CommandButton click event enter this code

Dim stDocName as String
Dim strFilter as String

strFilter = "qryFilter"
stDocName ="Check Request"
DoCmd.OpenReport stDocName, acViewNormal, strFilter

I advise you look at the Northwind orders form in design view and see the
code behind the print invoice Command Button
 
G

Guest

My report is not based on a query, but on a Form. Based on your
instructions, will I need to recreate the report? That I would rather not do
because this report is custom made. Thanks.

Muriukis said:
Ellie said:
HELP!

I am using the following code under the ComandButton to print the current
report from my form:

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 = "[Num] = " & Me.[Num]
DoCmd.OpenReport "Check Request", acViewNormal, , strWhere
End If

However, I keep getting the following error:

The expression On Click you entered as the event property setting produced
the following error: Object or class does not support the set of events.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

The first day I used it, it worked, but for some reason unknown to me, it
stop working. I haven’t made any changes. I’ve even tried recreating the
function, but still no luck. Would really appreciate some assistance.
Thanks.
Hi Ellie
One thing is not clear. Is the report based on a Query?
If it is and you want just to print the current records then I think you
should create a filter.

Example
Create a new query ie qryFilter
Use the the query which your report is based on and project the asteric * in
to the
new query first Column so that all fields are selected.
Hoping Num is the primary key in the second column project Num and in the
criteria area specify [Forms]![Formname]![txtNum]
Close this query and return to your form.
On the CommandButton click event enter this code

Dim stDocName as String
Dim strFilter as String

strFilter = "qryFilter"
stDocName ="Check Request"
DoCmd.OpenReport stDocName, acViewNormal, strFilter

I advise you look at the Northwind orders form in design view and see the
code behind the print invoice Command Button
 
G

Guest

Hi Ken,

Just wanted to let you know that I got my command to work. Another user
suggested that there might be some corruption. I created a new form,
inserted the code and it worked. Thanks for your help.

Ellie



Ellie said:
The code is in the button's On Click event--[Event Procedure]. This is
really wierd, because it worked the first day. Thanks.


Ken Sheridan said:
The code looks fine, and the error suggests that its not the code that's the
problem. What appears in the button's property sheet as the On Click event
property?

If, as is more likely, the code is in the button's Click event procedure
then it should say [Event Procedure] in the properties sheet. If on the
other hand the code is in a separate function you've created in the form's
module then the On Click event property should be the name of the function
preceded by an = sign and followed by parentheses:

=YourFunctionName()

Ken Sheridan
Stafford, England

Ellie said:
HELP!

I am using the following code under the ComandButton to print the current
report from my form:

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 = "[Num] = " & Me.[Num]
DoCmd.OpenReport "Check Request", acViewNormal, , strWhere
End If

However, I keep getting the following error:

The expression On Click you entered as the event property setting produced
the following error: Object or class does not support the set of events.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

The first day I used it, it worked, but for some reason unknown to me, it
stop working. I haven’t made any changes. I’ve even tried recreating the
function, but still no luck. Would really appreciate some assistance.
Thanks.
 

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