473,471 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unbound textbox to display Status Bar Text when control has focus

16 New Member
Good day,

I have racked my head against the wall so much over this I believe I have a flat spot....

Customer desires a form with a larger font for the Status Bar Text and located elsewhere on the screen - make shift instructions when a user clicks on a field.

While the simple answer is to utilize on.gotFocus and on.lostFocus the form has around 100 controls and not only a pain to code, but clutter is horrible.

I built a public function to grab the Screen.ActiveControl, however I would still have to code 200+ lines and makes the vba look horrid with that many lines of the same call function.


Any ideas or push in the right direction would be fantastic!

Thanks in advance,
Kendall
Oct 30 '17 #1

✓ answered by NeoPa

Hi Kendal.

I'm not seeing why your public function is complicated or long. Once you know the control simply grab its .StatusBarText property value and show it where you need to. If you're clever and use code to set up the function call for .OnGotFocus & .OnLostFocus to include the name of the control too then it can be even shorter. You do know you can call a public function directly from the properties don't you? And that public function can also be a method of the form too?

If that's no help how about sharing a few more details so we have a better understanding of what you're talking about.

5 2409
NeoPa
32,556 Recognized Expert Moderator MVP
Hi Kendal.

I'm not seeing why your public function is complicated or long. Once you know the control simply grab its .StatusBarText property value and show it where you need to. If you're clever and use code to set up the function call for .OnGotFocus & .OnLostFocus to include the name of the control too then it can be even shorter. You do know you can call a public function directly from the properties don't you? And that public function can also be a method of the form too?

If that's no help how about sharing a few more details so we have a better understanding of what you're talking about.
Oct 30 '17 #2
phillikl
16 New Member
Thanks Neo!

Forgot all about driving public functions from the properties. It's the easiest things that always get me - and being the only programmer, makes it hard to bounce ideas.

For anyone else requiring a solution similar:

create unbound text box of form (txtStatus)

set the properties to:

On Got Focus: =setStatusBarText()
On Lost Focus: =clearStatusBarText()

Public Functions:

Expand|Select|Wrap|Line Numbers
  1. 'Get data from the Status Bar Text field from the control and set it to unbound text box control
  2. Public Function setStatusBarText()
  3.  
  4. Dim ctlCurrentControl As Control
  5. Dim strControlName As String
  6.  
  7. On Error GoTo setStatusBarText_Err
  8. 'If control is not a drop down, just stop the code instead of throwing an error
  9. 'This is sloppy coding and control type should be pulled and executed with if/then statement
  10.  
  11.  
  12. Set ctlCurrentControl = Screen.ActiveControl
  13. strControlName = ctlCurrentControl.Name
  14.  
  15. Forms("frm_api").txtStatus = Forms("frm_api").Controls(strControlName).StatusBarText
  16. Forms("frm_api").Controls(strControlName).Dropdown
  17.  
  18. setStatusBarText_Exit:
  19.     Exit Function
  20. setStatusBarText_Err:
  21.     Resume setStatusBarText_Exit
  22.  
  23. End Function
  24.  
  25. Public Function clearStatusBarText() 'set the Status Bar Text control to empty
  26.  
  27. On Error GoTo clearStatusBarText_Err
  28.  
  29.     Forms("frm_api").txtStatus = Null
  30.  
  31. clearStatusBarText_Exit:
  32.     Exit Function
  33.  
  34. clearStatusBarText_Err:
  35.     Resume clearStatusBarText_Exit
  36.  
  37. End Function
  38.  
Thanks again,
Kendall
Oct 30 '17 #3
NeoPa
32,556 Recognized Expert Moderator MVP
Just so my earlier points were fully understood :
  1. The Public Function can be a Private Function and needn't be in a Standard Module. It can be referenced in the Module associated with the Form it's used by.
  2. I believe it's also possible to pass objects to such functions from the property sheet. IE. Instead of just the name of the item you can pass the Control itself and save the Function having to work it out for itself.

The code could be as simple as :
Expand|Select|Wrap|Line Numbers
  1. Private Function setStatusBarText(ctlVar As Control _
  2.                             , Optional ByVal blnSet As Boolean = True) As Boolean
  3.     Me.txtStatus = IIf(blnSet, ctlVar.StatusBarText, Null)
  4. End Function
So, you could set it up like :
On Got Focus: =setStatusBarText([ControlName])
On Lost Focus: =setStatusBarText([ControlName],False)

Some code run from the Immediate Pane (Ctrl-G) for Form=X & Controls=A, B & C might be :
Expand|Select|Wrap|Line Numbers
  1. S="A,B,C":For Each C In Split(S,","):Forms("X").Controls(C).OnGotFocus=Replace("=setStatusBarText([%C])","%C",CStr(C)):Forms("X").Controls(C).OnLostFocus=Replace("=setStatusBarText([%C],False)","%C",CStr(C)):Next C
Oct 31 '17 #4
phillikl
16 New Member
Thanks Neo! Will definitely add this to my toolbox of goodies!

Kendall
Nov 2 '17 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Always happy to help Kendall.

PS. I'll just delete that duplicate post for you ;-)
Nov 2 '17 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: thomaz | last post by:
I use the DataSource like below to fill a Combobox: comboBox1.DataSource = dataSet1.Tables; comboBox1.DisplayMember = "ProductName"; When the user types any keyboard key i use the DROPDOWN...
3
by: abc my vclass | last post by:
My win-form have many numericupdown controls to applied. But numericupdown control don't like textbox, text box control can automatic selected text when got focus. Is there any method can let me...
3
by: Pieter | last post by:
Hi, I'm making an Outlook (2003) Add-In (VB.NET 2005), with a simple button and a textbox (msoControlEdit). When the user types something in the textbox, and clicks on the button, the text in...
12
by: MLH | last post by:
Can I somehow set a max length of chars entered into an unbound textbox control?
3
by: Richard | last post by:
How is the result of query placed in a unbound textbox ? Suppose CriteriaLookups has columns TableName, KeyColumn, KeyValue, DataColumn Foo,x,11,xhat Bar,z,3,xyzzy And
9
by: arunbojan | last post by:
Hi friends, following is my code //================ if (ddlColumnName.SelectedItem.Text == "call duration") { Label4.Text = "HH:MM:SS";
3
by: Ghaime | last post by:
I have a form with an unbound textbox and after receiving a value, some checks should be done and maybe even some records inserted in the subform. All of that is going well, but the problem is that...
10
by: JohannKotzeVet | last post by:
Good day! I have a form in Access that has a multiple line textbox (I called it cAbnormalities). This text box is populated by the user ONLY through selection of options from combo boxes. I want...
2
bre1603
by: bre1603 | last post by:
I'm trying to run an UPDATE statement on a table that changes every time the user runs the code. Here's some info: (On a form) The user imports a text file, using a button to open a file browser...
7
by: DavidAustin | last post by:
Hi all, The database I am making is essentially for data entry of files and which boxes they have been placed into for storage. I have multiple textboxes on my form but I am only focused on a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.