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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignore (Cancel = True) Setting

Status
Not open for further replies.

grazer99

Programmer
Dec 19, 2007
7
GB
I have some code set at on exit() that stops the user entering Null as follows :

If IsNull(Me.Search) Then Cancel = True

works well where input is required, but i need to allow the form exit command button to be pressed, the command above doesn't allow this.

Is there any additional code i can use to recognise when the exit command button is clicked, in other words only overide the above coding if the exit button clicked.
 
Use a Boolean value? Set it to true when you click the command button, leave it as false if not. Then check the value in the Exit() Sub and allow or deny exit accordingly.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 

How about...
Code:
Dim Public bolExit as Boolean

Private Sub cmdExit_Click()
    bolExit = True
    [i]the rest of your code[/i]
End Sub
Change your current code
Code:
If bolExit Then
    If IsNull(Me.Search) Then
        Cancel = True
    End If
End If


Randy
 
Sorry it almost worked, allows me to now click the exit button, but allows the user to exit the text box for the input i.e. allows press enter to go to next control without entering anything,

i think this is because its processes the text box on-exit()totally before it recognises the on-click() of the close command button.

Private Sub Search_Exit(Cancel As Integer)

If cls Then
If IsNull(Me.Search) Then
Cancel = True
End If
End If
End Sub

Private Sub Closebutton_Click()
cls = True
DoCmd.Close
End Sub

This is the code i have used
 
Replace this:
If cls Then
with this:
If Not cls Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
because ive got cancel = true on the on_exit() of the text box its not allowing me to click the exit button.

the cancel = true works well stopping null input and remaining on that control, but i need to only overrride if the close form command button is clicked.
 
I have a small peer-peer setup with a database on 1 pc, another 3 users access the database.

Is there any way I can stop the same user from opening the database more than once ?

 
What strategy are you using to force the user into the textbox? The reason I ask is that you validation code will fail if the user simply doesn't enter the textbox. That why this type of validation is normally done int he form's BeforeUpdate event.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top