Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global events or event for all controls?

Status
Not open for further replies.

markphsd

Programmer
Joined
Jun 24, 2002
Messages
758
Location
US
Is there anyway to set a global event that will be triggers for all controls?

I wrote a mouseover procedure for some visual effect on controls, but I have to attach the code to each control for it to work. That's just too much work. I was thinking if I could set all controls globaly to have the effect then it would be worth using.

If there would be a better method I'd appreciate any suggestions.

Mark P.

Bleh
 
Maybe that wasn't clear enough.

What I'm try to do is have on every control a default included piece of code. Sort of like a default value for a field or control. This would result with every control being created would have a "gotFocus" event, and a "onMouseOver" event.

Mark P.

Bleh
 
set up a function in the module section which is none field or form specific the call it from the control you wish the operation to work from.
As an example:
This would be used in the Form Before Update
Function ConfirmUpdate()
MsgBox "This record has changed! Please confirm this is OK!", 3, "Confirm Update"
If vbQuestion = 6 Then
DoCmd.CancelEvent
End If
End Function

Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 
Its not a public function. I already have my public function set up. The problem is, I want to run the function on a ton of controls, across all the forms in my db, or future dbs.

I don't want to have to attach this code to each control. Therefore, is there anyway i can default the code to all controls on their mouse over and gotfocus event?


Mark P.

Bleh
 
Not that I know of but what about a function that went through every form ( a bit like TableDef) and did something with every control?

Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 

TrendSetter,

Sounds good, but I wouldn't know how to add an event to every control programmatically. I was just working on trying to loop through the forms like tabledef.. but I didn't figure that out yet.

But separate from looping all the forms, there's also: what happens once I get to the form? How would I then attach the function to all the controls. I could loop through the index of controls but then what, how would I associate the function with the control once I had the control name.

I found on some other site this code on how to make buttons appear to be xp buttons in apps that don't have the new xp styles. It works with vb, but not access. The was essentially one file, it resided in a windows folder, and it was like a .css. file. (cascading style sheets for the internet, the maintain a consisten formating across all pages by applying formats to control types and events on controls). The file crashed access, but i was hoping something similiar would work.

Thanks again.

Mark P.

Bleh
 
I know you guys have moved past the function posted by Trendsetter but I wanted to note that that function will not work as advertised I don't think. The use of vbQuestion is a parameter to indicate the kind of message box button arrangement and should not be used as the response or answer from the user. The function should look like this to perform the CancelEvent command if the user answers NO or a value of 7 for the MsgBox.
Function ConfirmUpdate()
Dim vResponse As Variant
vResponse = MsgBox("This record has changed! Please confirm this is OK!", 4, "Confirm Update")
If vResponse = 7 Then 'No response = 7 so cancel the event
DoCmd.CancelEvent
End If
End Function
I am not trying to but in here but found that code to not work as advertised and am just trying to clarify the mistake. If I am missing something her that I don't understand please get back with me on this.


Bob Scriver
 
If you used the Forms Collection to roll through each form within your app and then used code similar to:
Dim ctl As Access.Control
Dim objTxt As clsTextBox
Dim objCbo As clsComboBox
Dim objCmd As clsCommandButton
Dim objLst As clsListBox
Set fm = rfrm
For Each ctl In fm.Controls
If TypeOf ctl Is Access.TextBox Then
Enter code to set MouseOver to ....
Set objTxt = New clsTextBox
objTxt.Init ctl
mcolControls.Add objTxt
ElseIf TypeOf ctl Is Access.ComboBox InStrThen
Set objCbo = New clsComboBox
objCbo.Init ctl
mcolControls.Add objCbo
ElseIf TypeOf ctl Is Access.CommandButton Then
Set objCmd = New clsCommandButton
objCmd.Init ctl
mcolControls.Add objCmd
ElseIf TypeOf ctl Is Access.ListBox Then
Set objLst = New clsListBox
objLst.Init ctl
mcolControls.Add objLst
End If
Next

Bob,
The Function was not an intended piece of code to ACtually work but to demonstrate a function callable from any form easily.
I do apologise if this caused confusion it was purely meant to demonstrate an idea and not to be functional.
Sorry once again.........

Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 
No problem Frank, just didn't want someone picking that up and being confused by it and thinking they were not understanding. No serious criticism intended here. Good luck with this project.

Bob Scriver
 
Okay, I re-found the code that sort of what I'm looking to do.


The problem was, it crashed Access. Maybe I should try again.

It didn't have to create the xp style controls, but I thought I would be cool if I could manipulate the style across the board.

I think I'll have to focus back on this sort of solution. And try not to break any copyright.

Mark P.

Bleh
 
Trendsetter,

Thanks for the form collection tip.

Mark P.

Bleh
 
Hey everyone,

I also found this. Are you guys familiar with the "microsoft theme api type library" ? It's a reference I found, but I don't know how to use it. Well I'll more research on that also. Just pre-checking.

Mark P.

Bleh
 
Okay, another addition before I leave. Maybe this if anyone who reads this will have any additional notes to help me out.

The manifest file doesn't seem to effect Access. Why is that? Is it because Access doesn't recognize the intCommonControls(a vb, or common controls, function vb uses) function? If it doesn't recognize that function, is there some way of importing it, or re-writing it?
Will Access 2003 three have the xp style?





Mark P.

Bleh
 
I have done something simular, where I modify various properties of the control on got focus and on lost focus I used the Screen.ActiveControl.[whatever property i want] to reference the control which is currently active and made all the nessecary changes.

Hope this helps

Gavin,
 
Update:

I have XP Styles on office XP....
...on some controls. I have xp styles on the tab controls, on the alert boxes. and scroll bars. It is really wierd. Also, on the Access environment the xp styles are showing up, the access window looks kind of funny with the styles added. I'm working on the buttons and the text boxes.

Pretty much all I have done is add the manifest file. But somehow I have to call intCommonControls when access loads. I'm not sure how to do that. Any suggestions?

GavinJB.
Yes, I have the rolloever functions down. It works well. However, in order to get it to work i would have to set the proceducers on all controls on all forms. End result, big pain. So I'm focusing on XP Styles.



Mark P.

Bleh
 
Well, Access 2002 was leaking memory all over my desk when I got some of the XP styles working. Maybe the next access will have it.

It seems no one has any idea how to write a global format for all controls. Well, peace out on this post.

Mark P.

Bleh
 
Hey gavinjb

Thanks for that previous post on rolling through. I thought that would be a bigger pain then it was. Your code didn't work as you promised, but it was the idea that counts.

Anyways, i wrote a sendkeys function that rolls through all the forms and inserts my function. Right now i just have it placed in the immediate window. I end up with a page or two of code. That was a cool idea.

Now I have to figure out how to either skip the controls that already have a GotFocus procedure, or a mouseMove procedure. Or skip any procedure that has been written.
And, I don't really want to skip it completely, If it has been written i would like to insert the a line into the procedure, in a safe place, maybe right below the beginging of the sub.

Mark P.

Bleh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top