DoCmd.Close is not working.

  • Thread starter lsimonelli via AccessMonster.com
  • Start date
L

lsimonelli via AccessMonster.com

I have the following code on the 'On Click' event of a command button.

Private Sub Command34_Click()
If (Me.[Refund To/Apply To] = "Other" And IsNull(Me.[Comment B])) Then
MsgBox "You must enter explanation in box 13."
Me.[Comment B].SetFocus
Cancel = True
End If
If (Me.[Refund To/Apply To] = "Producer" And IsNull(Me.[Producer Code])) Then
MsgBox "You must enter Producer Code in box 7."
Me.[Producer Code].SetFocus
Cancel = True
End If
If (Me.[Action] = "Payment Misapplied to Policy" And IsNull(Me.[Misapplied
Policy Number])) Then
MsgBox "You must enter Mis-applied Policy Number in 10."
Cancel = True
End If
If (Me.[Action] = "Payment Misapplied to Policy & Needs to be Reinstated" And
IsNull(Me.[Misapplied Policy Number]) And IsNull(Me.[Reinstatement Date]))
Then
MsgBox "You must enter Misapplied Policy in 10 and Reinstatement Date in 11."
Cancel = True
End If
If (Me.[Action] = "Policy Needs to be Reinstated" And IsNull(Me.
[Reinstatement Date])) Then
MsgBox "You must enter Reinstatment Date in 11."
Cancel = True
End If
If (Me.[Refund To/Apply To] = "Other" And Not IsNull(Me.[Comment B])) And (Me.
[Refund To/Apply To] = "Producer" And Not IsNull(Me.[Producer Code])) And (Me.
[Action] = "Payment Misapplied to Policy" And Not IsNull(Me.[Misapplied
Policy Number])) And (Me.[Action] = "Payment Misapplied to Policy & Needs to
be Reinstated" And Not IsNull(Me.[Misapplied Policy Number]) And Not IsNull
(Me.[Reinstatement Date])) Then
DoCmd.Close
MsgBox "Your request has been submitted."
End Sub

The DoCmd.Close is not working. I'm sure it is in the last IF statement
because if I remove it, it works. Any ideas as to what is wrong with it?
 
F

fredg

I have the following code on the 'On Click' event of a command button.

Private Sub Command34_Click()
If (Me.[Refund To/Apply To] = "Other" And IsNull(Me.[Comment B])) Then
MsgBox "You must enter explanation in box 13."
Me.[Comment B].SetFocus
Cancel = True
End If
If (Me.[Refund To/Apply To] = "Producer" And IsNull(Me.[Producer Code])) Then
MsgBox "You must enter Producer Code in box 7."
Me.[Producer Code].SetFocus
Cancel = True
End If
If (Me.[Action] = "Payment Misapplied to Policy" And IsNull(Me.[Misapplied
Policy Number])) Then
MsgBox "You must enter Mis-applied Policy Number in 10."
Cancel = True
End If
If (Me.[Action] = "Payment Misapplied to Policy & Needs to be Reinstated" And
IsNull(Me.[Misapplied Policy Number]) And IsNull(Me.[Reinstatement Date]))
Then
MsgBox "You must enter Misapplied Policy in 10 and Reinstatement Date in 11."
Cancel = True
End If
If (Me.[Action] = "Policy Needs to be Reinstated" And IsNull(Me.
[Reinstatement Date])) Then
MsgBox "You must enter Reinstatment Date in 11."
Cancel = True
End If
If (Me.[Refund To/Apply To] = "Other" And Not IsNull(Me.[Comment B])) And (Me.
[Refund To/Apply To] = "Producer" And Not IsNull(Me.[Producer Code])) And (Me.
[Action] = "Payment Misapplied to Policy" And Not IsNull(Me.[Misapplied
Policy Number])) And (Me.[Action] = "Payment Misapplied to Policy & Needs to
be Reinstated" And Not IsNull(Me.[Misapplied Policy Number]) And Not IsNull
(Me.[Reinstatement Date])) Then
DoCmd.Close
MsgBox "Your request has been submitted."
End Sub

The DoCmd.Close is not working. I'm sure it is in the last IF statement
because if I remove it, it works. Any ideas as to what is wrong with it?

Regarding > The DoCmd.Close is not working<

Just a helpful tip to help you get good responses when asking
questions in newsgroups.
Words like 'That didn't work' or 'not working' gives any potential
reader who might want to help you absolutely no useful information.
What didn't happen?
What did happen?
What did you expect to happen?

Answers to those questions would be helpful to us .... to help you!

I haven't looked through the entire code, but a command button's click
event does not have a Cancel argument, so this line ( I see you use it
more than once) ...
Cancel = True
will error out.

If you were using the Option Explicit statement at the top of your
code, Access would have highlighted this line and given you an error
message.

This kind of code (including the Cancel = True lines) belongs in the
form's BeforeUpdate event, or the Form's Unload event, depending upon
what you are doing. Those events include a Cancel argument.
 
L

Linq Adams via AccessMonster.com

As Fred said, this type of validation code belongs in the Form_BeforeUpdate
event. This will keep the user from leaving the record in an inappropriate
state whether closing the form or moving to another record.

There's a couple of problems with your


DoCmd.Close

code. You're saying

If (Me.[Refund To/Apply To] = "Other" And ... (Me. [Refund To/Apply To] =
"Producer" ...

Me.[Refund To/Apply To] obviously cannot be "Other" And "Producer" both,
so this statement will ***never*** evaluate to True, hence the

DoCmd.Close

will never execute!

You do the same thing with Me.Action. And your

If...Then...

has no

End If statement
 

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