StepCart
asked on
Validate Event Seeming to cancel with cancel = false
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?
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
ASKER
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.
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.mblnIsPasswordC hanged 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.
I see some problem here in this code(may be my perspective)
Load frmChngWrd
frmChngWrd.txtUserName = gstrOwners
frmChngWrd.Show vbModal
If frmChngWrd.mblnIsPasswordC
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.
ASKER
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.
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.
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.
Ideally we should have Exit Sub called before error handler and error handler should be called in case there are errors.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My understanding is Validate event is only called when you try to change focus to other control.