I have a form with a command button. If the form is open as a child, I want to make the command button invisible. How do I sense when the form is open as a child?
I have a form with a command button. If the form is open as a child, I want to make the command button invisible. How do I sense when the form is open as a child?
Try this code in the Form_Load event of your main form
It assumes your button is in the subform
NOTE: I took this code from a thread at another forum https://www.access-programmers.co.uk...d.php?t=297204Code:Private Sub Form_Load()Dim Ctrl As Control For Each Ctrl In Me.Controls Select Case Ctrl.ControlType Case acSubform Ctrl.Form.btnToHide.Visible = False End Select Next Ctrl End Sub
Several other good ideas in the same thread
This worked................
Code:Private Sub Form_Open(Cancel As Integer) If HasParent Then Me.cmdHERE.Visible = False Me.lblHere.Visible = False End If End Sub Private Sub cmdHERE_Click() strmappingret = ExcelToAccess Me.Requery If Len(strmappingret) > 0 Then MsgBox "Highlighted names require correction." End If End Sub Private Property Get HasParent() As Boolean On Error GoTo handler HasParent = TypeName(Me.Parent.Name) = "String" Exit Property handler: End Property
Excellent. That was Mark Klein's code I believe.
I've not tried his code myself but was involved in that thread
BTW if the label is associated with the button you shouldn't need to specify that as well
Yes, I do that frequently with column headings to control data sorting. I isolated the "HERE" command from the surrounding text purposefully because I know how the users of the current App like to hover over text while they read.You can of course use a label as a command button with its own click event
You could also use:
Code:Private Sub Form_Load() If SysCmd(acSysCmdGetObjectState, acForm, "YourFormName") = 0 Then CommandButtonName.Visible = False Else CommandButtonName.Visible = True End If End Sub
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007