Solved

Got Focus/Lost Focus Procedure

Posted on 1998-09-10
7
502 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

747 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

16 Experts available now in Live!

Get 1:1 Help Now