Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Validate Event Seeming to cancel with cancel = false

Posted on 2009-03-31
6
Medium Priority
?
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

597 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