473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Auto-Generate Control Events on Form Load

Megalog
378 Expert 256MB
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 3053
DonRayner
489 Expert 256MB
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 Expert 2GB
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_MouseMove 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,556 Expert Mod 16PB
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 Expert 256MB
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,556 Expert Mod 16PB
Did you have a ControlTip Text value set for the control you were testing on?
Feb 11 '09 #6
NeoPa
32,556 Expert Mod 16PB
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
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...
1
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...
5
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...
9
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...
20
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
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...
22
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...
2
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...
1
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...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.