By Pass Validation Rule

Zurich98

New member
Local time
Today, 09:29
Joined
Oct 25, 2006
Messages
9
I've the following validation code on a data entry form


Private Sub CboCommCode_Exit(Cancel As Integer)

If IsNull(Me.CboCommCode) Or Me.CboCommCode = "" Then
MsgBox "Community is required! Enter community or select from list!"
Me.Undo
Cancel = True
End If

End Sub

after the user fills in the required info and press the add button, i clear the form and set the focus back to Me.CboCommCode for the user to add the next community. the problem i'm facing is when the user wants to quit and click the close button, the above validation rule kick in and ask for a community since i clear it and the user will have to enter something in the Me.CboCommCode then click the close button to exit. How can I tell Access if a close button is click, ignore the validation rule? Your help/suggestion is greatly appreciated.

Thanks
 
First create an unbound checkbox named chkClose and set its visible property to false

Next add the below code to your close button

me.chkClose=True


Next replace your validation rule with below


Private Sub CboCommCode_Exit(Cancel As Integer)
if me.chkClose<>True then
If IsNull(Me.CboCommCode) Or Me.CboCommCode = "" Then
MsgBox "Community is required! Enter community or select from list!"
Me.Undo
Cancel = True
End If
end if

End Sub
 
Keith,

Thanks for a quick response. i did what you suggested and i receive this message:

run-time error: '438' : Object doesn't support this property or metho.

i click debug and this line of code is highlighted:

me.chkClose=True
 
What is the error?


try
if isnull(me.chkClose)=true then
 
the error is
run-time error: '438' : Object doesn't support this property or method.

just point to a different line.

i just try isnull(me.chkClose) = True then...

no error. however, when i click close button, i get this message:

Object does not support this property or method.

the application will not let me do anything. so i have to click file and close out Access. thanks
 
Can you post an example so I can have a look? Did you maybe name the label to the checkbox chkClose instead of the actual check box?
 
you are absolutely right. i make a mistake naming the label instead of the check box. i right click on the check box (has green check in the middle) and select properties and change the Name to chkClose. now when i click close button, nothing happen. form not close. what else can i try. thanks
 
Sound like there is a syntex error in your code try adding some error handling so that a error will be produced. Also are you trying the code from my original post?
 
its not me.chkclose - thats a property

if its a field its

me!chkclose = true
or just chkclose = true
 
i still can not get this to work. if i already have a code behind the close button as follow:

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

DoCmd.Close


Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub


why do i need to creat a check box and how does the check box value get change? can you help me understand this? thanks
 

Users who are viewing this thread

Back
Top Bottom