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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy control event handler across forms

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I seem to have an update/dirty issue on a form.

I have event handlers for update / dirty and change on a textbox (memo) field.

I also have a double click event which opens up a 'zoom' form which binds the control to it in a larger format for large text entry.

However, when the data is changed in the 'zoom' window and copied back to the undelying form and field, the event handlers for that field aren't triggered?

Why?

Is it possible to dynamically copy form field event handlers between forms?

Or what other alternative can I use to ensure the event handler is fired?

thanks,

1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
Events only fire through the user interface not things done programmatically.

To fire the event you have to call it. Although I think most events are private, so you will have to add a procedure to call the event to the existing form...

Say you had a form named frmDemo with a list box lstExample whose after update event you wanted to call. You might add the following to frmDemo's module...

Code:
Public Sub frmDemoLstExample_Change()
    On Error GoTo frmDemoLstExample_Change_err
    lstExample_AfterUpdate
Exit Sub
frmDemoLstExample_Change_err:
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error in frmDemoLstExample_Change On " & Me.Name
End Sub


Then when you set the listbox programmatically you might call that sub...

Code:
Forms!frmDemo!lstExample = <SomeValue>
Call Forms("frmDemo").frmDemoLstExample_Change


Note that I only included the form name in the new procedure for clarity. You might also be able to make it work by changing the private to public on the event itself but I did not test that and I expect this would collide with other forms using the same technique eventually.
 
Thanks lameid.

The issue is the zoom function is generic which can be applied to *any* field on *any* form.

The last thing I want to do is start adding VB code to the zoom 'popup' form specific to just when a certain field calls upon the 'zoom' function.

Also the zoom function can be used just to open up a textbox entry so it's easier to read. the content might not actually get changed, so I don't want to call a function which updates a 'someone changed something' table, when they didn't!

I guess I could add an additional parameter to the 'zoom' function call for any function that needs to be ran afterwards.

I'll have to have a long hard think over how to implement this without breaking anywhere the 'zoom' feature is currently implemented!






"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top