raise event of access control

V

vdavid

Hello,

I have some code who put event catchers on a control to do some AfterUpdate
stuffs like this :

Dim WithEvents myTrigger1 as CheckBox
....
set MyTrigger1 = Me.myCtrl
....
Private Sub myTrigger1_AfterUpdate()
....
End Sub

there is many catchers like this my form don't know about.

OK it works well. My form don't need and can't know who catch events. Event
are done for this. But sometimes, i need to change by program the value of
myCtrl. Without the event catchers I wrote, I only need to call
myCtrl_AfterEvent(). But with, all AfterEvent methods of the catchers need
to be called. I'd like to do a "raiseEvent" for AfterEvent, but this can't
be called outside the object who declare the event (here the TextBox
itself...)

Any idea ? (get the event queue for an object, or another paradigm...)
 
R

rkc

vdavid said:
Hello,

I have some code who put event catchers on a control to do some AfterUpdate
stuffs like this :

Dim WithEvents myTrigger1 as CheckBox
...
set MyTrigger1 = Me.myCtrl
...
Private Sub myTrigger1_AfterUpdate()
...
End Sub

there is many catchers like this my form don't know about.

OK it works well. My form don't need and can't know who catch events. Event
are done for this. But sometimes, i need to change by program the value of
myCtrl. Without the event catchers I wrote, I only need to call
myCtrl_AfterEvent(). But with, all AfterEvent methods of the catchers need
to be called. I'd like to do a "raiseEvent" for AfterEvent, but this can't
be called outside the object who declare the event (here the TextBox
itself...)

Any idea ? (get the event queue for an object, or another paradigm...)

I'm not sure I really understand what you want to do. I think you want
add your own custom events to a control and raise them when one or
more of the controls built in events fire. You can do that by creating
a class that contains the control object. Example code is below.

You use it in a forms module by creating an instance of the class
and passing it the control you want to watch.


<Form level code>
Private WithEvents oWatcher as clsWatchEvents

Private Sub Form_Load
Set oWatcher = new clsWatchEvents
oWatcher.Init (Me.Checkbox1)
End Sub

Private Sub oWatcher_AfterEvent(sEvent As String)
'code that runs when any watched event fires
Debug.Print sEvent
End Sub

</Form level code>

<clsWatchEvents>
Option Compare Database
Option Explicit

Private WithEvents m_cb As Access.CheckBox
Public Event AfterEvent(sEvent As String)

Public Sub Init(cb As Access.CheckBox)
Set m_cb = cb
m_cb.OnClick = "[Event Procedure]"
m_cb.OnDblClick = "[Event Procedure]"
m_cb.OnGotFocus = "[Event Procedure]"
End Sub

Private Sub m_cb_Click()
RaiseEvent AfterEvent("Click")
End Sub

Private Sub m_cb_DblClick(Cancel As Integer)
RaiseEvent AfterEvent("Double Click")
End Sub

Private Sub m_cb_GotFocus()
RaiseEvent AfterEvent("Got Focus")
End Sub

</clsWatchEvents>
 
V

vdavid

Thank you for your answer. I had already think about a wrapper, but, but,
but... I looked for a more fancy trick to raise directly the event on the
control... Access is not Java or C++, I must put this in my head... (and it
is for this we like it...)


rkc said:
vdavid said:
Hello,

I have some code who put event catchers on a control to do some AfterUpdate
stuffs like this :

Dim WithEvents myTrigger1 as CheckBox
...
set MyTrigger1 = Me.myCtrl
...
Private Sub myTrigger1_AfterUpdate()
...
End Sub

there is many catchers like this my form don't know about.

OK it works well. My form don't need and can't know who catch events. Event
are done for this. But sometimes, i need to change by program the value of
myCtrl. Without the event catchers I wrote, I only need to call
myCtrl_AfterEvent(). But with, all AfterEvent methods of the catchers need
to be called. I'd like to do a "raiseEvent" for AfterEvent, but this can't
be called outside the object who declare the event (here the TextBox
itself...)

Any idea ? (get the event queue for an object, or another paradigm...)

I'm not sure I really understand what you want to do. I think you want
add your own custom events to a control and raise them when one or
more of the controls built in events fire. You can do that by creating
a class that contains the control object. Example code is below.

You use it in a forms module by creating an instance of the class
and passing it the control you want to watch.


<Form level code>
Private WithEvents oWatcher as clsWatchEvents

Private Sub Form_Load
Set oWatcher = new clsWatchEvents
oWatcher.Init (Me.Checkbox1)
End Sub

Private Sub oWatcher_AfterEvent(sEvent As String)
'code that runs when any watched event fires
Debug.Print sEvent
End Sub

</Form level code>

<clsWatchEvents>
Option Compare Database
Option Explicit

Private WithEvents m_cb As Access.CheckBox
Public Event AfterEvent(sEvent As String)

Public Sub Init(cb As Access.CheckBox)
Set m_cb = cb
m_cb.OnClick = "[Event Procedure]"
m_cb.OnDblClick = "[Event Procedure]"
m_cb.OnGotFocus = "[Event Procedure]"
End Sub

Private Sub m_cb_Click()
RaiseEvent AfterEvent("Click")
End Sub

Private Sub m_cb_DblClick(Cancel As Integer)
RaiseEvent AfterEvent("Double Click")
End Sub

Private Sub m_cb_GotFocus()
RaiseEvent AfterEvent("Got Focus")
End Sub

</clsWatchEvents>
 
R

rkc

vdavid said:
Thank you for your answer. I had already think about a wrapper, but, but,
but... I looked for a more fancy trick to raise directly the event on the
control... Access is not Java or C++, I must put this in my head... (and it
is for this we like it...)

Like it or not VBA is what you have to work with in Access and delegation
and containment are the only ways to extend a class in VBA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top