setting a control property on a "called" form

M

Mark Kubicki

I have a form [sfrmCalledForm] that can be called from several different
control buttons on another form [frmMainForm].
Depending on what control was triggered, different controls on
[sfrmCalledForm] should either (be / or not be) enabled.

I'm trying this code, but fear i may be in the wrong approach:
this code is written behind the control's click event on frmMainForm

On Error GoTo Err_EditFixtureInfo_Click
Dim stDocName As String
stDocName = ...
Dim stLinkCriteria As String
stLinkCriteria = ...
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmMainForm.Controls!cmdNewFixture.Enabled = False
...

any suggestions?

thanks in advance,
mark
 
A

Allen Browne

Instead of repeating this code in many forms that could call this one, it
might be better to use the Load or Open event of the sfrmCalledForm to
enable/disable the controls based on the name of the form that called it.

To do that, you could pass the name of the calling form in OpenArgs, like
this:
DoCmd.OpenForm stDocName, WhereCondition:= stLinkCriteria, _
OpenArgs:=Me.Name

Then respond in sfrmCalledForm's Load event, like this:

Private Sub Form_Load()
Select Case Me.OpenArgs
Case "Form1"
Me.cmbNewFixture.Enabled = True
Case "Form2"
Me.cmbNewFixture.Enabled = True
Case Else
'whatever
End Select
End Sub
 
J

Julia B

Hi I'm not sure I understand what you've done but here's a suggestion.

If you've got 3 controls that open sfrmCalledForm, you could do open it with
different open args e.g.

control 1 click event - DoCmd.OpenForm sfrmCalledFor, , , , , , "Control1"
control 2 click event - DoCmd.OpenForm sfrmCalledFor, , , , , , "Control2"
control 3 click event - DoCmd.OpenForm sfrmCalledFor, , , , , , "Control3"

Then in sfrmCalledForm's on open event you could do this:

dim formMode as string
formMode = Me.OpenArgs

If formMode = "Control1" then
button1.visible = true
ElseIf formMode = "Control2" then
button1.visible = true
Else
button1.visible = false
End If

Hope this helps.

Julia
 
M

Marshall Barton

Mark said:
I have a form [sfrmCalledForm] that can be called from several different
control buttons on another form [frmMainForm].
Depending on what control was triggered, different controls on
[sfrmCalledForm] should either (be / or not be) enabled.

I'm trying this code, but fear i may be in the wrong approach:
this code is written behind the control's click event on frmMainForm

On Error GoTo Err_EditFixtureInfo_Click
Dim stDocName As String
stDocName = ...
Dim stLinkCriteria As String
stLinkCriteria = ...
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmMainForm.Controls!cmdNewFixture.Enabled = False
...


It is normally too soon for the calling form to set
properties in the called form. The general approach should
be to pass an argument in the OpenForm method so the called
form can set its own properties:
DoCmd.OpenForm stDocName, , , stLinkCriteria, _
OpenArgs:= "A"
then the called form can use code like this in its Open or
Load event:
Select Case Me.OopenArgs
Case "A"
Me.cmdNewFixture.Enabled = False
Case "B"
. . .
 

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