Calling form - detect control from which launched

G

Gordon

I have a form which can be called from a number of other forms.
Depending on the calling form, different actions are perfomed in the
called form. I use the following code in the load event of the called
form:

Private Sub Form_Load()
Dim frmCalling As Form
Set frmCalling = Screen.ActiveForm

Select Case frmCalling.Name

Case "frmDiscs"
etc etc

Case "frmVocalArrangements"
..etc etc.

Case Else
...
.....
End Select
End Sub

The problem I have is that on frmDiscs, the form can be called from 2
different controls (in fact in a subform of frmDiscs). Again,
depending upon which control the form is being called from (by a
double click event), I want to perform different actions when the
called form is loaded.

How can I achieve this? Is there a way I can put a case statement
within the first case statement above to determine the control that is
firing the event?

Thanks for any help.

Gordon
 
A

Allen Browne

You will need to pass some information from the calling form to the target
form, e.g.:
DoCmd.OpenForm "Form2", OpenArgs:="frm='Form1';clt='Text0'"

Then parse the OpenArgs with Split to get the information you need.

Alternatively, if the target form is not being opened modally, you could put
a couple of hidden text boxes on it, and push the information there, e.g.:
DoCmd.OpenForm "Form2"
With Forms("Form2")
!txtCallingFrm = "Form1"
!txtCallingCtl = "Text0"
End With

A third possiblity (if you actually need a reference to the control, which
could be on a subform) would be to declare a public variable in a standard
module:
Public txtSearchTarget As TextBox
and then set it before calling your search form:
Set txtSearchTarget = Me.[Sub1].Form![Text0]
DoCmd.OpenForm "Form2"
and you can then refer to it later.
 
G

Gordon

Thanks Allen,

You've given me quite a bit of food for thought there. I think the
multiple openargs route is the best option for me. I've never used it
with the split function so that should be a good learning experience
for me. I'll get back if I have any problems :))

Thanks again.

Gordon
 
A

Allen Browne

Here's a quick demo of how Split() creates an array from a string, by
breaking it at a delimiter (comma in the example):

Function DemoSplit()
Dim aVar() As String
Dim i As Integer
Dim strSource As String

strSource = "abc, ddd, 12q, q8, 66666, dog"
aVar() = Split(strSource, ", ")
For i = 0 To UBound(aVar())
Debug.Print aVar(i)
Next
End Function
 

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