Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Thu Feb 13 04:42:00 CST 2003
> So, does anyone know how to accomplish the same thing in Access 97. Drew, It looks a little bit ugly but it can be done in Acc97 and ported to A2K/AXP/A11 with just a few edits of the source code - here is one of the ways to do it: '================ cut here ================== '+ CMyClassWithEvents (custom class module) #Const Acc97 = 1 ' change to 0 in A2K/AXP/A11 #If Acc97 Then Private mobjCallBackClient As Object Public Sub Init(ByRef robjCallBackClient As Object) Set mobjCallBackClient = robjCallBackClient End Sub Public Sub Terminate() Set mobjCallBackClient = Nothing End Sub #Else 'Event MyEvent() ' uncomment in A2K/AXP/A11 #End If Public Sub CallBackTest() #If Acc97 Then mobjCallBackClient.MyEvent #Else 'RaiseEvent MyEvent ' uncomment in A2K/AXP/A11 #End If End Sub '- CMyClassWithEvents '================ cut here ================== '+ CMyCustomsEventsClient (custom class module) #Const Acc97 = 1 ' change to 0 in A2K/AXP/A11 #If Acc97 Then Private mobjMyClassWithEvents As CMyClassWithEvents #Else Private WithEvents mobjMyClassWithEvents As CMyClassWithEvents #End If Public Sub Test() Set mobjMyClassWithEvents = New CMyClassWithEvents With mobjMyClassWithEvents #If Acc97 Then .Init Me .CallBackTest .Terminate #Else .CallBackTest #End If End With End Sub Private Sub mobjMyClassWithEvents_MyEvent() MsgBox "MyEvent fired!", vbOKOnly + vbInformation End Sub #If Acc97 Then Public Sub MyEvent() mobjMyClassWithEvents_MyEvent End Sub #Else #End If '- CMyCustomsEventsClient '================ cut here ================== '+ basTest (standard module) Public Sub a_test() Dim o As CMyCustomsEventsClient Set o = New CMyCustomsEventsClient o.Test End Sub '- basTest '================ cut here ================== - Of course you can set project level conditional compilation constant Acc97 to have less work during your port to A2k/Axp/A11; - Unfortunately Event and RaiseEvent are reserved words in Acc97 and even conditional compilation doesn't allow to use them without comments - so during port to A2k/Axp/A11 additional work of uncommenting code lines with RaiseEvent and Event will be needed...; - I did use very simple custom event without any arguments to show the principle - in the case of the usage of event arguments callback methods can be specific for every custom event or this technique can use more general callback method with EventName as the first paramater and ParamArray following it and Select Case inside it to call specific private custom event sinks ...; - Init method is what MS Access does "behind the curtains" when you use WithEvents; - Terminate method is a MUST HAVE for this custom events Acc97 simulation - without it object instances will not be released because of cross-refs and you'll get memory leak.... HTH, Shamil ----- Original Message ----- From: "Drew Wutka" <DWUTKA at marlow.com> To: <AccessD at databaseadvisors.com> Sent: Thursday, February 13, 2003 7:49 AM Subject: [AccessD] Off the wall Events question... > With all of the posts about events recently, something just dawned on me. > Actually, it came crashing down on me. > > I have been rewriting my MiniCalendar form lately. My original works, but > is far from elegant, or even slick. I had visualized a lot of changes I > wanted to incorporate, and just starting wacking at them all. > > So far I have gotten some neat 'features', such as a rounded form, extended > dropdown capability, etc. However, one of the new features that I had > planned on, I now know I can't do directly. The old form accepted a form > name and control name, and would return a date to that control. What I > wanted to use in this version was raiseevent, to fire an event on the > calling form. Thinking in VB 6 mode, I didn't even realize this would be a > problem with Access 97, since I can do this easily in VB 6. But with all of > the recent posts, I realized that event and raiseevent are reserved keywords > in Access 97 (VBA 5.0), but do nothing. > > ARG!!!! > > So, does anyone know how to accomplish the same thing in Access 97. I will > be making a 2000 version of my calendar, so obviously I can use event and > raiseevent there, but I am developing the new version in 97 first, so I need > a work around. I am thinking about using one of the form's current events, > and triggering it. (Probably AfterUpdate). I wanted my own event, but that > doesn't look possible. I even tried hunting through the VBA .dll's, to see > if I could fudge an API or two, but no luck there. > > Any thoughts? > > Drew > _______________________________________________ > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com