Solved

Got Focus/Lost Focus Procedure

Posted on 1998-09-10
7
504 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 115
Run code from text file in vb 1 64
Getting warning: You are about to delete 1 row(s) 9 48
VBA: copy range dynamically based on config sheet v2 3 31
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

785 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