Field validation upon a button press.

G

Guest

Hi guys,

I have a form which has a tick box called Approved. I have a button which
when clicked prints the current record in a report. I want the form to
display an error message whenever the button is clicked if Approved is not
ticked. I have the code:

Private Sub Command41_Click()
Dim stDocName As String

If [Approved] = "0" Then
MsgBox "You are trying print an un-approved quotation. Get it checked!",
vbQuestion + vbOK, "Warning"
End If

stDocName = "Quotations"
DoCmd.OpenReport "quotations", acViewNormal, , "[QuotationID] = " &
Me![QuotationID]


Exit_Quotation_Report_Print_Preview_Clic:
Exit Sub

Err_Quotation_Report_Print_Preview_Click:
MsgBox Err.Description
Resume Exit_Quotation_Report_Print_Preview_Clic
End Sub

Which sort of works, but when I click cancel on the error message, the
document still prints. Also if I cancel the print I get the error message:

Runtime Error '2501'
The open report action was cancelled.

Can someone correct my code for me? Thanks in advance.
 
G

Guest

hi
try
if me.check1 = true then
msgbox"fuss fuss"
exit sub
end if
the way you have it set up the report will print
regardless of the checkbox condition or message.
so through in a exit sub after the message which will
bypass the print code.
-----Original Message-----
Hi guys,

I have a form which has a tick box called Approved. I have a button which
when clicked prints the current record in a report. I want the form to
display an error message whenever the button is clicked if Approved is not
ticked. I have the code:

Private Sub Command41_Click()
Dim stDocName As String

If [Approved] = "0" Then
MsgBox "You are trying print an un-approved quotation. Get it checked!",
vbQuestion + vbOK, "Warning"
End If

stDocName = "Quotations"
DoCmd.OpenReport "quotations",
acViewNormal, , "[QuotationID] = " &
Me![QuotationID]


Exit_Quotation_Report_Print_Preview_Clic:
Exit Sub

Err_Quotation_Report_Print_Preview_Click:
MsgBox Err.Description
Resume Exit_Quotation_Report_Print_Preview_Clic
End Sub

Which sort of works, but when I click cancel on the error message, the
document still prints. Also if I cancel the print I get the error message:

Runtime Error '2501'
The open report action was cancelled.

Can someone correct my code for me? Thanks in advance.
.
 

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