problem with subform

  • Thread starter Thread starter Michael Hanlon
  • Start date Start date
M

Michael Hanlon

Ok I have a sub form that I would like to hide depending on the password
give by the user.
The main form name is Pers and the sub form name is Pers info. I tryed it
this way but no joy
The main form opens and the filter works but the subform is still there.
any help would be great thanks in advance.


DoCmd.OpenForm "pers", acNormal, ,"[department] = 1" , , , "pers
info.visible = false"
 
Michael,

The OpenArgs argument simply sends a string (text data) to the OnOpen Event
of the form. If your OnOpen event doesn't do something with the data,
nothing will happen. I would put the visible = false code in the Onopen
event like this:

Private Sub Form_Open(Cancel As Integer)
On Error Goto Err_Sub

If Not 0 = InStr(1, Me.OpenArgs, "HideSF") Then Me![pers info].Visible =
False

Exit_Sub:
Exit Sub
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub

and open the form like this:
DoCmd.OpenForm "pers", acNormal, ,"[department] = 1" , , , "HideSF"

But if you want to send code in the OpenArgs instead, then you can use the
eval function in the OnOpen event of the form like this (not recommended):

Private Sub Form_Open(Cancel As Integer)
On Error Goto Err_Sub

Eval(Me.OpenArgs)

Exit_Sub:
Exit Sub
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub

Also, please note you need brackets around the subfrom name because there is
a space in the name. Generally one you should try to avoid spaces for that
reason. The code also assumes the subform container object on the main form
is called 'pers info' as it won't work if the only the source object of the
container is called 'pers info'.

HTH,
Josh
 
Back
Top