[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

LostFocus and the Toolbar

Posted on 1998-08-03
4
Medium Priority
?
453 Views
Last Modified: 2012-05-04
I have an MDI app with a toolbar.  The code in ButtonClick for the Save button simply calls the save functionality on the active child form.  I also have placed textbox field-level validation throughout the app in the lostfocus subroutines.

The problem:  If I enter data into a given textbox BUT DO NOT TAB OFF then press the save button on the toolbar, the save functionality gets fired without the field-level validation getting fired.  The result is that invalid data can get saved to the database.

Question:  How can I get the field-level validation to fire in the described scenario?  It is not acceptable to do field-level validation at save time.

Using setfocus to change the focus to another control does not fire the lostfocus on the original control (already tried to do this).

Basically, since the Toolbar is on the MDI form, clicking a button on it does not make the control on the Child form lose focus.  How do I get around this?
0
Comment
Question by:csmyser
[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
  • 2
  • 2
4 Comments
 

Author Comment

by:csmyser
ID: 1467690
Edited text of question
0
 
LVL 2

Accepted Solution

by:
percosolator earned 100 total points
ID: 1467691
You are using MS's ToolBar?  Tried it myself, and you are right, it doesn't work.

Several options:

   Look into Activbar (it's slick), but I haven't encountered a problem like this with Activebar, so I don't have an immediate answer (will try it at work tomorrow)


   If you don't have, are using, or don't want to buy Activebar, then put extra validation code into the button click event of your toolbar.

I ran a test with MS's toolbar.  Created a form with "Text1" and "Text2", and a MS toolbar.  In the toolbar, I created a button with the Key = "Test"

Code follows.
-------

Option Explicit

Private Sub Text1_LostFocus()

    If (Not IsNumeric(Text1)) Then
   
        MsgBox "Text1 is not numeric"
       
        Text1 = ""
       
        Text1.SetFocus
       
    End If
   
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)

    If (Button.Key = "Test") Then
   
        If (Not IsNumeric(Text1)) Then
       
            MsgBox "Text1 is not numeric"
           
            Text1 = ""
           
            Text1.SetFocus
           
        End If
       
    End If
   
End Sub
----

That should help you out.  If your validation is more extensive than a basic IsNumeric check, put it into a function or subroutine.
0
 

Author Comment

by:csmyser
ID: 1467692
If you have the chance to see if this works with Activebar, I'd love to know.

As for putting the code behind the button, it is one of our discussed options.  However, we are building a large application with many areas and a host of field-level validations.  Putting the code in the save button, but not firing each field's validation at save time, will require a lot of case statements, etc, because only the field in which the user was last in would need to have the validation run at save time.

I appreciate your response, however.
0
 
LVL 2

Expert Comment

by:percosolator
ID: 1467693
Active bar does the same thing.  Lemme try something else.


--------------------okay------------------------------

try this on for size.  Same as before with Text1, Text2
and Toolbar1

------------------------------------------------------
Option Explicit

Dim mblnCancel As Boolean
Private Sub Text1_LostFocus()

    If (Not IsNumeric(Text1)) Then
   
        mblnCancel = True
       
        MsgBox "Text1 is not numeric"
       
        Text1 = ""
        Text1.SetFocus
       
    Else
       
        mblnCancel = False
       
    End If
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
   
    mblnCancel = False

    Screen.ActiveForm.ActiveControl.SetFocus
    SendKeys "{TAB}"
    DoEvents
   
    If (mblnCancel) Then Exit Sub
   
    MsgBox "This won't show if Text1 is not numeric"

End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

656 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