another "print current record" question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've been through the gamut of other threads responding to similar requests,
and have been unable to find a solution that works. From a form, I want to
click a command button, and have a coversheet print out with the current
record's info only.

The following code (courtesy of Allen Browne's response to another) gives me
an error - "The expression On Click you entered as the even property setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line below, I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
Under Prop -> Name, it shows butPrintCoversheet

Rick B said:
Is your button named "cmdPrintCoversheet"?


--
Rick B



Chester B said:
I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I want
to
click a command button, and have a coversheet print out with the current
record's info only.

The following code (courtesy of Allen Browne's response to another) gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
Then why did you put "cmdPrintCoversheet" in your code?

If you want the code to run when you click something called
"butPrintCoversheet" then that is what should be in your "click" event.

--
Rick B



Chester B said:
Under Prop -> Name, it shows butPrintCoversheet

Rick B said:
Is your button named "cmdPrintCoversheet"?


--
Rick B



Chester B said:
I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I
want
to
click a command button, and have a coversheet print out with the
current
record's info only.

The following code (courtesy of Allen Browne's response to another)
gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line
below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
BTW - I really appreciate your help.

Rick B said:
Then why did you put "cmdPrintCoversheet" in your code?

If you want the code to run when you click something called
"butPrintCoversheet" then that is what should be in your "click" event.

--
Rick B



Chester B said:
Under Prop -> Name, it shows butPrintCoversheet

Rick B said:
Is your button named "cmdPrintCoversheet"?


--
Rick B



I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I
want
to
click a command button, and have a coversheet print out with the
current
record's info only.

The following code (courtesy of Allen Browne's response to another)
gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line
below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
I put "cmdPrintCoversheet" in my code and get the same error. I just tried
changing the name of both the button and the subform to cmdPrintCover; now
instead of the original error, it prompts me for DocumentID. I've
double-checked, and that name is consistently and correctly used in the form
and in the button code from what I can see.
Then why did you put "cmdPrintCoversheet" in your code?

If you want the code to run when you click something called
"butPrintCoversheet" then that is what should be in your "click" event.

--
Rick B



Chester B said:
Under Prop -> Name, it shows butPrintCoversheet

Rick B said:
Is your button named "cmdPrintCoversheet"?


--
Rick B



I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I
want
to
click a command button, and have a coversheet print out with the
current
record's info only.

The following code (courtesy of Allen Browne's response to another)
gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line
below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
edit - by "correctly" I meant no misspellings. Clearly I'm not using it
right somewhere though.

Chester B said:
I put "cmdPrintCoversheet" in my code and get the same error. I just tried
changing the name of both the button and the subform to cmdPrintCover; now
instead of the original error, it prompts me for DocumentID. I've
double-checked, and that name is consistently and correctly used in the form
and in the button code from what I can see.
Then why did you put "cmdPrintCoversheet" in your code?

If you want the code to run when you click something called
"butPrintCoversheet" then that is what should be in your "click" event.

--
Rick B



Chester B said:
Under Prop -> Name, it shows butPrintCoversheet

:

Is your button named "cmdPrintCoversheet"?


--
Rick B



I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I
want
to
click a command button, and have a coversheet print out with the
current
record's info only.

The following code (courtesy of Allen Browne's response to another)
gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line
below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
please try...



Private Sub butPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub


You do have a field in your form (and on the report) called "DocumentID",
right?

Your report is named "rptPCCoversheet", correct?



--
Rick B



Chester B said:
Under Prop -> Name, it shows butPrintCoversheet

Rick B said:
Is your button named "cmdPrintCoversheet"?


--
Rick B



Chester B said:
I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I
want
to
click a command button, and have a coversheet print out with the
current
record's info only.

The following code (courtesy of Allen Browne's response to another)
gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line
below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 
Ok, problems solved. The first one was caused by me having an extra copy of
the "private sub..." line after the "end sub" statement; it was fine after I
deleted it.

The second problem (not recognizing the ID field) was caused (I think) by
the fact that the report was sourced by a query of the form's source - not
the same source itself. I fixed it by changing the record source to the same
as the form.

Mad props to Rick Daddy for insights into the nature of events, and to
Stanley-Bostitch and Acco for producing sturdy staplers and paper clips with
which I can think when frustrated.

Chester B said:
edit - by "correctly" I meant no misspellings. Clearly I'm not using it
right somewhere though.

Chester B said:
I put "cmdPrintCoversheet" in my code and get the same error. I just tried
changing the name of both the button and the subform to cmdPrintCover; now
instead of the original error, it prompts me for DocumentID. I've
double-checked, and that name is consistently and correctly used in the form
and in the button code from what I can see.
Then why did you put "cmdPrintCoversheet" in your code?

If you want the code to run when you click something called
"butPrintCoversheet" then that is what should be in your "click" event.

--
Rick B



Under Prop -> Name, it shows butPrintCoversheet

:

Is your button named "cmdPrintCoversheet"?


--
Rick B



I've been through the gamut of other threads responding to similar
requests,
and have been unable to find a solution that works. From a form, I
want
to
click a command button, and have a coversheet print out with the
current
record's info only.

The following code (courtesy of Allen Browne's response to another)
gives
me
an error - "The expression On Click you entered as the even property
setting
produced the following error: Ambiguous name detected: cmdPrint
Coversheet_Click". When I try changing the name in the first line
below,
I
get no error, but nothing at all happens.

Private Sub cmdPrintCoversheet_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 = "[DocumentID] = " & Me.[DocumentID]
DoCmd.OpenReport "rptPCCoversheet", acViewPreview, , strWhere
End If
End Sub

Thanks for reading this far,
 

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

Back
Top