AfterUpdate Msgbox...

AuroX7

Registered User.
Local time
Today, 09:07
Joined
Feb 22, 2006
Messages
44
I have a field on my form which I want to display a message box when something is entered.

Private Sub BoI_AfterUpdate()

Box = Msgbox("Is the booking date at least 7 days before the hiring and no more than 8 weeks in advance? If so, click Yes, otherwise, click No. You can check the calender on the Open Form under the 'Miscellanous' tab to check the date. Thank you.", vbYesNo, "Validation")
If Box = vbYes Then Cancel = False
Else
Cancel = True
End If

End Sub

That's my code, but I get an error after I type something in that field (BoI).
"Compile error: Else without If" I have tried it with 'ElseIf Box = vbNo Then Cancel = True' but that also gives the same error.

What's wrong with it?

Thanks in advance. :D
 
Last edited:
AuroX7 said:
I have a field on my form which I want to display a message box when something is entered.

Private Sub BoI_AfterUpdate()

Box = Msgbox("Is the booking date at least 7 days before the hiring and no more than 8 weeks in advance? If so, click Yes, otherwise, click No. You can check the calender on the Open Form under the 'Miscellanous' tab to check the date. Thank you.", vbYesNo, "Validation")
If Box = vbYes Then Cancel = False
Else
Cancel = True
End If

End Sub

That's my code, but I get an error after I type something in that field (BoI).
"Compile error: Else without If" I have tried it with 'ElseIf Box = vbNo Then Cancel = True' but that also gives the same error.

What's wrong with it?

Thanks in advance. :D

First off need to declare your Box variable

Dim Box as String or as boolean, which ever you prefer.


Try this:

Code:
Private Sub BoI_AfterUpdate()
Dim Box as string

Box = Msgbox("Is the booking date at least 7 days before the hiring and no more than 8 weeks in advance? If so, click Yes, otherwise, click No. You can check the calender on the Open Form under the 'Miscellanous' tab to check the date. Thank you.", vbYesNo, "Validation")

' 6 is yes 7 equals no
If Box = "6" Then 
me.Cancel = False
Else
me.Cancel = True
End If

End Sub

Also, what is cancel. You need to reference it something like me.cancel.

HTH
 
Also, the update can't be cancelled in the after update event. You want the before update event.
 
Private Sub BoI_AfterUpdate()
Dim Box As String

Box = Msgbox("Is the booking date at least 7 days before the hiring and no more than 8 weeks in advance? If so, click Yes, otherwise, click No. You can check the calender on the Open Form under the 'Miscellanous' tab to check the date. Thank you.", vbYesNo, "Validation")
' 6 is yes 7 equals no
If Box = "6" Then
BoI.AfterUpdate = BoI
Else
BoI.Text = ""
End If

End Sub

The Yes bit works, but when I click No I get a runtime error saying 'the macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Access from saving the data in the field.'

Any ideas?
Nearly there, lol. :D
 
Repeating post 3, and wondering why you don't validate the date yourself, presuming you have access to both of them.
 

Users who are viewing this thread

Back
Top Bottom