Hello all, I'm a newbie to VBA, and am slowly picking it up, but I need some help on this one! The basic situation is this: I have a form (form1) which contains a combo box that is Limited to List. OnNotInList, a Sub will ask the user if they wish to add a new value. If yes, a form opens (form2) and goes to a new record for them to add the information. (there are several fields, so using a second form is the easiest way for me to accomplish this) Once data is input on form2, on close, I need to requery the combo box, which is done through another sub attached to the OnClose event of form2.
The problem is that form2 is also used to just view the data it contains, separate from being opened by form1. So I need to be able to determine if form1 is opened, if so, requery my combo box, if not, just close the form. Here's what I'm working with so far, though I'm certain this isn't the best way to tackle this one:
Private Sub Form_Close()
'Can I nest this function in a sub? If not, what is the easiest way to determine if the form is opened in this sub?
Function IsLoaded(ByVal strFormName As String) As Boolean
'Returns True if the specified form is open in form view or datasheet view
Const OBJ_STATE_CLOSED = 0
Const DESIGN_VIEW = 0
If SysCmd(acSysCmdGetObjectState, acForm, Forms![frm01-01Master]![frm02-02CasesSUB]) <> OBJ_STATE_CLOSED Then
If Forms([frm01-01Master]![frm02-02CasesSUB]).CurrentView <> DESIGN_VIEW Then
IsLoaded = True
End If
End If
End Function
Forms![frm01-01Master]![frm01-02CasesSUB].Form!AssFacilityCode.Requery
Forms![frm01-01Master]![frm01-02CasesSUB].Form!TreatFacilityCode.Requery
End Function
The problem is that form2 is also used to just view the data it contains, separate from being opened by form1. So I need to be able to determine if form1 is opened, if so, requery my combo box, if not, just close the form. Here's what I'm working with so far, though I'm certain this isn't the best way to tackle this one:
Private Sub Form_Close()
'Can I nest this function in a sub? If not, what is the easiest way to determine if the form is opened in this sub?
Function IsLoaded(ByVal strFormName As String) As Boolean
'Returns True if the specified form is open in form view or datasheet view
Const OBJ_STATE_CLOSED = 0
Const DESIGN_VIEW = 0
If SysCmd(acSysCmdGetObjectState, acForm, Forms![frm01-01Master]![frm02-02CasesSUB]) <> OBJ_STATE_CLOSED Then
If Forms([frm01-01Master]![frm02-02CasesSUB]).CurrentView <> DESIGN_VIEW Then
IsLoaded = True
End If
End If
End Function
Forms![frm01-01Master]![frm01-02CasesSUB].Form!AssFacilityCode.Requery
Forms![frm01-01Master]![frm01-02CasesSUB].Form!TreatFacilityCode.Requery
End Function