Identify index from any loaded form

G

Guest

Is there a way that when a form is loaded, it identifies which other form it
was opened from? I was hoping there was something that could identify the
loaded form, and then pass the index (which will always have the same field
name) to the new record.

What I'm looking for is something like this -- where RecordID is the field
name linking the parent and child:

Private Sub Form_Load()
RecordID = [Forms]![(something to identify which form the new form was
loaded from)]![RecordID]
End Sub
 
G

Guest

Why not reverse the logic and 'push' the id in the RecordID like:

When form A needs to open

Docmd.openform "form A"
forms!formA!recordID= me.recordID
docmd.close "form" -> the form that delivers the me.recordID

When form B need to open
Docmd.openform "form B"
forms!formB!recordID= me.recordID
docmd.close "form" -> the form that delivers the me.recordID

etc..

That way you are pushing instead of pulling and you would never have to
reveal any id from any form...
 
D

Dirk Goldgar

In
NickyG said:
Is there a way that when a form is loaded, it identifies which other
form it was opened from? I was hoping there was something that could
identify the loaded form, and then pass the index (which will always
have the same field name) to the new record.

What I'm looking for is something like this -- where RecordID is the
field name linking the parent and child:

Private Sub Form_Load()
RecordID = [Forms]![(something to identify which form the new form was
loaded from)]![RecordID]
End Sub

Maurice's answer is a good alternative. However, you can also take
advantage of the fact that, in the Open event of the newly opened form,
the form that opened it is still the active form as far as Access is
concerned -- the new form hasn't been activated yet. So you could use
the Open event to capture the name of that form or other information
from it, like this:

'---- start of form's module -----
Option Compare Database
Option Explicit

Dim mvarCallingRecordID As Variant

Private Sub Form_Open(Cancel As Integer)

On Error Resume Next
mvarCallingRecordID = Screen.ActiveForm!RecordID

End Sub

Private Sub Form_Load()

Me!RecordID = mvarCallingRecordID
' or maybe this should be deferred to the Current event?

End Sub
'---- end of form's module -----

I wouldn't wait until the Load event to capture information from the
calling form using Screen.ActiveForm -- it might work (I haven't tried
it), but it might be too late.
 
G

Guest

That worked beautifully -- thank you so much!

Dirk Goldgar said:
In
NickyG said:
Is there a way that when a form is loaded, it identifies which other
form it was opened from? I was hoping there was something that could
identify the loaded form, and then pass the index (which will always
have the same field name) to the new record.

What I'm looking for is something like this -- where RecordID is the
field name linking the parent and child:

Private Sub Form_Load()
RecordID = [Forms]![(something to identify which form the new form was
loaded from)]![RecordID]
End Sub

Maurice's answer is a good alternative. However, you can also take
advantage of the fact that, in the Open event of the newly opened form,
the form that opened it is still the active form as far as Access is
concerned -- the new form hasn't been activated yet. So you could use
the Open event to capture the name of that form or other information
from it, like this:

'---- start of form's module -----
Option Compare Database
Option Explicit

Dim mvarCallingRecordID As Variant

Private Sub Form_Open(Cancel As Integer)

On Error Resume Next
mvarCallingRecordID = Screen.ActiveForm!RecordID

End Sub

Private Sub Form_Load()

Me!RecordID = mvarCallingRecordID
' or maybe this should be deferred to the Current event?

End Sub
'---- end of form's module -----

I wouldn't wait until the Load event to capture information from the
calling form using Screen.ActiveForm -- it might work (I haven't tried
it), but it might be too late.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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