Ignore Form Event

GendoPose

Registered User.
Local time
Today, 10:08
Joined
Nov 18, 2013
Messages
175
Hi all,

In my database I have module that checks if tick box is True and then closes all the forms and kicks the user out of the database. However in most of my forms, there is a custom Save command in the On Click of cmdSave button and the Form_BeforeUpdate. The save requires certain things to be true so naturally if a user has made a change to a record, the form won't allow you to close it if you haven't saved your changes or undone them.

Is there anyway I can get my module to bypass certain events in the form?

Thanks
 
You might need a Public flag, that will denote where it is called from. If the flag is set then the bypass needs to be done, if not it should be considered.
 
You might need a Public flag, that will denote where it is called from. If the flag is set then the bypass needs to be done, if not it should be considered.

See I tried something like that, in the top of every form's code I have this;

Code:
Public txtClicked As String

This is set to "No" when the form is dirty and when the save button is hit, it's set to "Yes" to allow the save function to continue. In the module, I tried using the same flag and setting it to "Yes" before it tries to close the form but I still then get the BeforeUpdate event firing as if it still is "No"?
 
You need a whole new Flag, setting a variable to Public inside a Form Module will be still a local variable, i.e. the scope of the variable is only limited as long as the Form is alive. Public variables that are declared in a Standard Module will be available all throughout the application.

So create a flag in the Module, and the code in all form modules (unfortunately) now has to use this flag to be checked first.
 
Last edited:
You need a whole new Flag, setting a variable to Public inside a Module will be still a local variable, i.e. the scope of the variable is only limited as long as the Form is alive. Public variables that are declared in a Module will be available all through the application.

So create a flag in the Module, and the code in all form modules (unfortunately) now has to use this flag to be checked first.

So at the top of this module I'd put

Code:
Public whatever As String

and then in each form I have to replace with "txtClicked" with "whatever"? The Public flag is declared at the top of each form too so would I have to delete that or also change that to "whatever"?
 
No ! Your form flag stays as it is, you create the "whatever" flag in the module and then in your form BeforeUpdate you will use.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If whatever = "No" Then
       [COLOR=Green] 'This section denotes that the code is called from the form within.[/COLOR]
        If txtClicked = "Yes" Then
            [COLOR=Green]'Code to Allow close[/COLOR]
        Else
           [COLOR=Green] 'Code to warn user to click the txtClicked[/COLOR]
        End If
    Else
       [COLOR=Green] 'Code to Allow close, as it is called from the module[/COLOR]
    End If
End Sub
 
No ! Your form flag stays as it is, you create the "whatever" flag in the module and then in your form BeforeUpdate you will use.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If whatever = "No" Then
       [COLOR=green]'This section denotes that the code is called from the form within.[/COLOR]
        If txtClicked = "Yes" Then
            [COLOR=green]'Code to Allow close[/COLOR]
        Else
           [COLOR=green]'Code to warn user to click the txtClicked[/COLOR]
        End If
    Else
       [COLOR=green]'Code to Allow close, as it is called from the module[/COLOR]
    End If
End Sub

Brilliant, that's got it! Thank you so much!
 

Users who are viewing this thread

Back
Top Bottom