Solved

Got Focus/Lost Focus Procedure

Posted on 1998-09-10
7
509 Views
Last Modified: 2010-05-18
A procedure that uses "Got Focus" and "Lost Focus".  It needs to get the "Property Name" and use that name as a variable to set the Font.Name=True (False on the Lost Focus)
0
Comment
Question by:matthewkwp
[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
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:bharris1
ID: 1434088
What EXACTLY are you looking for?  Explain in detail.
0
 

Author Comment

by:matthewkwp
ID: 1434089
I have a form with 12 text boxes on it.  When a person moves from one text box to another I want the font to change to Bold.  Like wise when the focus is lost, the font will go back to normal.  I want to do a procedure, not having to code each text box.  The idea is to treat the property name as a variable and change the font according to text.box name.
0
 
LVL 1

Accepted Solution

by:
bharris1 earned 100 total points
ID: 1434090
In a module:
Public Sub SetBold(txtBox as TextBox)
    txtBox.FontBold = True
End Sub

Public Sub SetNormal(txtBox as TextBox)
    txtBox.FontBold = False
End Sub


In each GotFocus/LostFocus event:

Private Sub Text1_GotFocus()
    SetBold Text1
End Sub

Private Sub Text1_LostFocus()
    SetNormal Text1
End Sub

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Expert Comment

by:dapperry
ID: 1434091
BHarris1's answer (He beat me to the 'Submit' button)  insists on you putting a lot of code.  Try my answer instead:
Instead of using the property name (which I don't think you can do) why don't you create a control array of text boxes.  Then there is a single got focus, and a single lost focus event.  You can then determine which box is losing or getting the focus, by getting the value of index.
Code would look like this.

Private Sub Text1_LostFocus(Index As Integer)
          Text1(Index).Font.Bold=false
End Sub

Private Sub Text1_GotFocus(Index As Integer)
          Text1(Index).Font.Bold=true
End Sub

Let me know if you have any questions.

:) D Perry
0
 
LVL 1

Expert Comment

by:bharris1
ID: 1434092
This would work great if the TextBoxes were in a control array.

0
 

Author Comment

by:matthewkwp
ID: 1434093
Thank you both for your help.  At my level (or lack there of) bharris's works for me.  Sorry D Perry >:(, when you start getting into arrays it is beyond me at this point. Thanks D Perry for your time
0
 
LVL 3

Expert Comment

by:dapperry
ID: 1434094
BHarris1's answer (He beat me to the 'Submit' button)  insists on you putting a lot of code.  Try my answer instead:
Instead of using the property name (which I don't think you can do) why don't you create a control array of text boxes.  Then there is a single got focus, and a single lost focus event.  You can then determine which box is losing or getting the focus, by getting the value of index.
Code would look like this.

Private Sub Text1_LostFocus(Index As Integer)
          Text1(Index).Font.Bold=false
End Sub

Private Sub Text1_GotFocus(Index As Integer)
          Text1(Index).Font.Bold=true
End Sub

Let me know if you have any questions.

:) D Perry
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month9 days, 23 hours left to enroll

623 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