Solved

Validate Event Seeming to cancel with cancel = false

Posted on 2009-03-31
6
426 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

24 Experts available now in Live!

Get 1:1 Help Now