Solved

Validate Event Seeming to cancel with cancel = false

Posted on 2009-03-31
6
425 Views
Last Modified: 2013-11-25
I have a form that has an OK button. When the OK button is pressed it activates a textboxes validate event. There is nothing in the validate event that changes the value of the cancel parameter. However, the click code for the OK button doesnt run after the validate event. It must be click again (when the validate command is not run) to get it to run.

I have enclosed code below. Any idea's what would cause this?
Private Sub txtOwnersWord_Validate(Cancel As Boolean)
 

    Const I_SAY_SO = False

    Const PROC_NAME = "txtOwnersWord_Validate"

    gMyEH.StartRoutine mMODULE_NAME & "." & PROC_NAME

    On Error GoTo Err_txtOwnersWord_Validate

    

    If IsOurAreaWordValid(gstrOwners, "") Then

        gstrMBMessage = "This is the first login for the [" & gstrOwners & _

	"] account since a " & vbCrLf & "password reset. A new password must be entered now."

        gintMBType = vbOKOnly

        Beep

        Call MsgBox(gstrMBMessage, gintMBType, "Validation Error")

        Load frmChngWrd

        frmChngWrd.txtUserName = gstrOwners

        frmChngWrd.Show vbModal

        If frmChngWrd.mblnIsPasswordChanged Then

            gstrOwners = frmChngWrd.txtUserName

            txtDBOwnerName = gstrOwners

            gstrDBOwnerPwd = frmChngWrd.txtNewPassword

            chkChngWrd = 0

        End If

        Unload frmChngWrd

    End If

    

    'If the user has entered a password for the db owner then of course the

    'user wants to login in the db owner.

    If Not txtOwnersWord = "" And Not chkAcceptOwner = 1 Then

         chkAcceptOwner = 1

    End If

    

    If I_SAY_SO Then

        Cancel = True

    End If
 

Exit_txtOwnersWord_Validate:

    On Error GoTo Err_txtOwnersWord_Validate

    gMyEH.EndRoutine mMODULE_NAME & "." & PROC_NAME

    Exit Sub
 

Err_txtOwnersWord_Validate:

    gMyEH.Raise Err.Number, _

        Source:=mMODULE_NAME & "." & PROC_NAME

    Resume Exit_txtOwnersWord_Validate
 

End Sub

Open in new window

0
Comment
Question by:StepCart
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:deepakra79
ID: 24048130
can you tell how clicking on Ok button, would call Validate Event of textbox?
My understanding is Validate event is only called when you try to change focus to other control.
0
 
LVL 1

Author Comment

by:StepCart
ID: 24049669
The OK button is a command button control and the validate event should be activated if when the text box looses focus. Still don't understand why the OK button's click event isn't being activated after the code in text box control's validate event is run.
0
 
LVL 1

Expert Comment

by:deepakra79
ID: 24057724
I do not think Validate Event as such is causing problem.

I see some problem here in this code(may be my perspective)

Load frmChngWrd
frmChngWrd.txtUserName = gstrOwners
frmChngWrd.Show vbModal
If frmChngWrd.mblnIsPasswordChanged Then
gstrOwners = frmChngWrd.txtUserName
txtDBOwnerName = gstrOwners
gstrDBOwnerPwd = frmChngWrd.txtNewPassword
chkChngWrd = 0
End If
Unload frmChngWrd


I do not know what is code present inside frmChngWrd. You are showing it as a VBModal. Isn't it unloaded when u come out of line "frmChngWrd.Show vbModal"? Then u r again caling same form to retrieve the different values and then calling Unload method. Please confirm Form_Unload event is not callled 2 times.

Also there is a code "gMyEH.StartRoutine mMODULE_NAME & "." & PROC_NAME" Is it something which is calling something that runs in background. This may take its focus. This would impact similar to calling DoEvents.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:StepCart
ID: 24059885
The section of code you refer to that loads the frmChngWrd, doesn't usually run. When the user logs in using the form that this code is in, it tests whether the user is a member of the MyDBAdmins group. If this is true, then it shows the text box for the control that contains this validate event. If the user then supplies the MyDBOwner account's password then this validate event should run.

My system does not allow blank password. If a user logs in and no password exists it automatically brings up the frmChngWrd object to force them to change it. I have not tested recently what happens in the event of a blank password for the MyDBOwner account. The problem I am experience now occurs while this code is never run. Though, I should say additionally that when I am experiencing this problem I am not attempting to log in the MyDBOwner account and therefore not entering any data in the password textbox, so really the validate event should not even be running.

As for the gMyEH.StartRoutine (sorry about the names but I have changed the names of my objects for displaying here to limit any liability for showing company property). This is a custom class object for error handling that has a debug mode. All it does (when debug mode is on) is display in the immediate pane an entry for starting and ending all the routines indented based on it's level in the stack. I strongly doubt that this is causing the problem.
0
 
LVL 1

Expert Comment

by:deepakra79
ID: 24060093
One more thing I see here, the error handlers are called 2 times. Also, there is no Exit Sub called before the error handler. May be it keeps it in loop for some before exiting the routine.
Ideally we should have Exit Sub called before error handler and error handler should be called in case there are errors.
0
 
LVL 1

Accepted Solution

by:
StepCart earned 0 total points
ID: 24132738
I think I have found the answer. Though I don't really understand it. I had an unhandled exception in the function IsOurAreaWordValid() which had error trapping set to resume next. When I changed that function so that the error no longer happened, the validate event code would run and then continue with the cmdOK_Click code.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now