Form sync via custom events independent of order of form opening

J

John F

I have two forms that are synchronized. frmA raises a custom event that frmB
listens to. Right now, this only works if frmA is opened prior to frmB. I
would like this to also work if frmB is opened first but am having problems
implementing this.

------------------------

In frmA, the custom event is declared:

Public Event MoveSubm(strSeqNo As String)

The event is raised in when the On Current event within frmA occurs:

Private Sub Form_Current()

'Raise event to signal to frmB
RaiseEvent MoveSubm(Me.txtSeqNo)

DoEvents

End Sub


------------------------


Within frmB, I declare:

Dim WithEvents frmSub As Form_frmA

Then when frmB loads,

Private Sub Form_Load()

'Set the frmSub object
Set frmSub = Form_frmA

End Sub

Then the routine that executes within frmB when the event in frmA is raised:

Private Sub frmSub_MoveSubm(strSeqNo As String)

…

End Sub

------------------------

I realize the reason the way I have this implemented is when the frmB load
event occurs, if frmA is not already loaded, there is nothing to Set frmSub
to. I tried moving

Set frmSub = Form_frmA

to other events, but without success.

Any suggestions to allow the synchronization if frmB opens prior to frmA?

Thanks,

John
 
D

dneagle via AccessMonster.com

John said:
I have two forms that are synchronized. frmA raises a custom event that frmB
listens to. Right now, this only works if frmA is opened prior to frmB. I
would like this to also work if frmB is opened first but am having problems
implementing this.

------------------------

In frmA, the custom event is declared:

Public Event MoveSubm(strSeqNo As String)

The event is raised in when the On Current event within frmA occurs:

Private Sub Form_Current()

'Raise event to signal to frmB
RaiseEvent MoveSubm(Me.txtSeqNo)

DoEvents

End Sub

------------------------

Within frmB, I declare:

Dim WithEvents frmSub As Form_frmA

Then when frmB loads,

Private Sub Form_Load()

'Set the frmSub object
Set frmSub = Form_frmA

End Sub

Then the routine that executes within frmB when the event in frmA is raised:

Private Sub frmSub_MoveSubm(strSeqNo As String)

…

End Sub

------------------------

I realize the reason the way I have this implemented is when the frmB load
event occurs, if frmA is not already loaded, there is nothing to Set frmSub
to. I tried moving

Set frmSub = Form_frmA

to other events, but without success.

Any suggestions to allow the synchronization if frmB opens prior to frmA?

Thanks,

John

Have a look at OpenArgs in the help. It might prove helpful.
 

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