Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Statement problem

Status
Not open for further replies.

sdimaggio

Technical User
Jan 23, 2002
138
US
I know the answer to this is easy, but I need a little help. I’m trying to get a form to close if a customer is on COD basis or they have an approval# that is inactive. My code is as follows embedded in an AfterUpdate event.

Private Sub

If Me![Approval#] = "Inactive" Then
MsgBox "This Approval Number is Inactive. " _
& " Call the Lab Manager.", vbInformation
Cancel = True
DoCmd.Close
End If

If Me![BillingStatus] = "COD" Then
MsgBox "This Customer is a DEAD BEAT. " _
& " Call the Accounting Department or Plant Manager.", vbInformation
Cancel = True
DoCmd.Close

End If
End Sub

The problem is I get a runtime error:

The expression you entered refers to an object that is closed or doesn’t exist.

The text: ( If Me![BillingStatus] = "COD" Then ) is highlighted in yellow.

Any help is appreciated.

 
Remember that Me![BillingStatus] should be the name of the control on the form. Have you checked that what you are referring to is this control and not the name of field that is the control source?
 
Yes, Me![BillingStatus] is the name of the control on the form.
 
Is it possible that you get the error when the form has already been closed because the Approval# was inactive?

Try using an exit sub after the first docmd.close or rephrasing as an else if.

HTH

John

Use what you have,
Learn what you can,
Create what you need.
 
exit sub

Worked like a charm!

Many Many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top