Problem understanding asynchronous processes

B

Browser

Hello,

I'm new to VBA and am having a problem understanding asynchronous processes.

I've a Form in Access that I want to start an out-of-process object that
will run, basically, on its own until stopped by an outside event.

My problem is that I don't understand how to start the object without
getting the Form caught waiting for the object to stop processing.

What I've done is create an ActiveX EXE component that houses two class
objects, one that does the work (called the FNCreator) and a wrapper class
(called the Creator).

In my Access form I create an instance of the Creator class and tell it to
create an instance of the FNCreator. When the Creator does this, it passes a
reference to itself, with events, to the FNCreator.

To start the FNCreator, the Access form calls Creator.Start. Creator.Start
then raises an event StartIt which is handled in FNCreator.

I thought that Creator.Start would fire the event and go to the next
instruction without jumping to FNCreator's StartIt() handler, but that is not
what happens. Instead Creator.Start gets caught waiting for the sub called by
the event to end and therefore doesn't return control to the Access form. How
would I implement this correctly?

I'd love to hear if anyone has a helpful suggestion or can point me in the
right direction for assisatance. Thanks!

My simplified code looks like this:

Access Form:

Private Sub Toggle0_Click()

If Toggle0.Value = True Then
...
Set myCreator = New Creator
...
myCreator.create "FN"
...
myCreator.start "FN"
Else
myCreator.ShutDown "FN"
End If

End Sub


Creator Class:

Private myFNCreator As FNCreator

Event FNStartIt()
Event FNStopIt()

Public Function Create(arg As String)

Select Case arg
Case "FN"
If Not myFNCreator Is Nothing Then
...
Else
Set myFNCreator = New FNCreator
Set myFNCreator.Parent = Me
...
End If
Case Else
...
End Select
End Function

Public Function Start(arg As String)

Select Case arg
Case "FN"
If Not myFNCreator Is Nothing Then
If myFNCreator.Active = False Then RaiseEvent FNStartIt
Else
...
End If
Case Else
...
End Select
End Function

Public Function ShutDown(arg As String)

Select Case arg
Case "FN"
If Not myFNCreator Is Nothing Then
...
RaiseEvent FNStopIt
Else
...
End If
Case Else
...
End Select
End Function


FNCreator Class:

Private booIsActive As Boolean
Private WithEvents myParent As Creator

Private Sub Class_Initialize()

booIsActive = False

End Sub

Private Sub Class_Terminate()

If Not myRecordset Is Nothing Then Set myRecordset = Nothing

End Sub

Friend Property Get Active() As Boolean

Active = booIsActive

End Property

Friend Property Set Parent(arg As Creator)

Set myParent = arg

End Property

Public Sub myParent_FNStartIt()

If booIsActive = True Then Exit Sub
booIsActive = True
...

Do While booIsActive = True
...
Loop
...
End Sub

Public Sub myParent_FNStopIt()

booIsActive = False

End Sub
 
L

Larry Daugherty

I think your issue is more in the sphere of ActiveX than of Access.

HTH
 

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