473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto-Generate Control Events on Form Load

Megalog
378 Recognized Expert Contributor
Hey guys, my turn to ask a question =D

Ok here's my situation.. I have a super simple form, which is bound to a table with a single record. All the controls (mostly text boxes, some true/false checkboxes and combos) are bound straight to each field.

Now, in the table itself, each field has it's Description property filled out, instructing the user as to what data belongs in the field. I can pull this data on the form by using each control's .StatusBarText property. What I'd like to do is have a label in the form header, that updates OnEnter in each control, showing the user the full description of the currently selected control. (It does display in the statusbar on the bottom, but it gets cut off usually.)

I -dont- want to plug in the code in each control's Enter/Leave/GotFocus, etc events. I want to auto-populate these on Form Load, or, maybe catch some other type of event when I switch focus between controls and then pass this to a generic function.

If this can be done on form load, I imagine I'd start with something like the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub SetControlEvents()
  2.     Dim i As Integer
  3.  
  4.     For i = 0 To Controls.count - 1
  5.             If Controls(i).ControlType = acTextBox Or Controls(i).ControlType = acComboBox Then
  6.                  'set event for control
  7.             End If
  8.     Next
  9.  
  10. End Sub
So, can dynamically written events be done like this? I understand I can use a single function to pass the name of the control, etc.. But this is being set up so that an end user can go into the table, enter new fields, type a description, and simply drop the new control onto the form and it'll work without having to enter in any events for it.
Feb 7 '09 #1
6 3072
DonRayner
489 Recognized Expert Contributor
Since it's a simple form as you say, why not just use the on timer event and check to see which control has the focus. If the focus has changed then change the label text. Something like this

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Public strPreviousField As String
  3.  
  4. Private Sub Form_Timer()
  5. If strPreviousField = Me.ActiveControl.Name Then
  6.     Exit Sub
  7. End If
  8.     strPreviousField = Me.ActiveControl.Name
  9.     Me.Label1.Caption = Me.ActiveControl.StatusBarText
  10. End Sub
Feb 7 '09 #2
FishVal
2,653 Recognized Expert Specialist
Hi, Megalog.

I had a same problem when was coding an interface feature based on mouse move over a certain control. The problem was the following - since form was overcrowded with controls, handling Detail_MouseMov e event was not reliable to detect when mouse pointer leaves control. So I've written a class (similar to that in this thread) that "merges" events from all form components.

See the attached demo.

Regards,
Fish.

P.S. Hmm. Unfortunately it seems impossible to attach anything so far. If you are interested to see the code, then PM me your mail.
Feb 7 '09 #3
NeoPa
32,564 Recognized Expert Moderator MVP
How about using the form's BeforeScreenTip event procedure.

If I understand your requirements correctly, you can check within the procedure that the ToolTip is one you're interested in (SourceObject Object) and, if it is, simply set the .Caption property of the label control to the value of the ScreenTipText object.
Feb 8 '09 #4
Megalog
378 Recognized Expert Contributor
Thanks guys
I ended up using a timer, which I normally avoid, since I couldnt find a form event that would work.

Neo, I couldnt get the BeforeScreenTip event to trigger.. I'm not sure what I was doing wrong, I'll try to revisit that event when I get more time. Never knew it existed before. =)
Feb 9 '09 #5
NeoPa
32,564 Recognized Expert Moderator MVP
Did you have a ControlTip Text value set for the control you were testing on?
Feb 11 '09 #6
NeoPa
32,564 Recognized Expert Moderator MVP
My bad.

I did some testing and some further research and found that it's only valid for PivotTables & PivotCharts :(
Feb 11 '09 #7

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

Similar topics

2
2593
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code that follows C++ RAII pattern. Of course Python objects are not statics like in C++, but in C++ the auto_ptr class is used for enforcing this...
1
13950
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the page the way I want. Does anybody know a solution for this? First of all, the code I am using: CSS ------- body {
5
6088
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge of the screen. I want it to only extend as far as it needs to to nicely contain the content within (a couple of links). Is width: auto the wrong...
9
2498
by: Alan Mackenzie | last post by:
To all those who use (X)Emacs's CC Mode to edit C, C++, Java, Objective-C, Pike, AWK or IDL: To help direct the development of CC Mode, it would be useful to find out how people use the auto-newline "minor mode" facility. If you could spare a little time, would you answer these questions, please: o Do you program with auto-newline...
20
2838
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
5
3253
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what...
22
3043
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly like that: int main(char argc, char *argv, char *env) { try { auto Exception mainException(1); mainException.setErrNo(42);
2
3060
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value ("auto") in JavaScript - however instead of getting "auto" value, I get calculated height. In IE and Opera it simply returns "auto". Any ideas how to...
1
2966
by: neridaj | last post by:
Hello, I've found a few postings of this problem but none of the answers seem to fix my problem. I have a content div wrapped around a left floated image and a right floated table. I want the table to dictate the height to the content div instead of popping out of the bottom of the content div. Seems pretty simple but too complicated for me I...
21
6312
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
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 we have to send another system
1
1212
muto222
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.