Is there any form property that we can use to inform VBA code that a form is open? If not, what could be a solution?
Is there any form property that we can use to inform VBA code that a form is open? If not, what could be a solution?
Can you give us a bit more detail abiut what you are trying to do.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Im not sure if i understand you correct and what the purpose might be, But there is a way to see if your form is opened on another location for example.
I would make a very basic table, for example tblOpenForm and then make a field called FormOpened.
Now, I would make a SQL statement that puts a value of 1 into that field when the form is opened.
Then, i would make a SQL statement that puts a value of 0 into that field when the form is closed.
Now you could make a field called fldFormOpened on your form that Dlookup's that value.
I may have the syntaxis a little off, but this is how i would do it.Code:Private sub form_current() If dlookup ("tblOpenForm", "FormOpened") = "0" then me.fldFormOpened.value = "The form is closed" else me.fldOpened.value = "the form is open" end sub
Maybe theres a simpler way though, not sure.
I've look to a related topic and it provided me an interesting function. See the code below.
Thanks.
Code:
Public Function funIsLoadedForm(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
On Error GoTo Error_funIsLoadedForm
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
funIsLoadedForm = True
End If
End If
Exit_funIsLoadedForm:
Exit Function
Error_funIsLoadedForm:
MsgBox "Error in funIsLoadedForm: " & Err.Number & " - " & Err.Description
Resume Exit_funIsLoadedForm
End Function