B
BruceM
I have several forms that need to be opened from several locations within a
database. When the form is opened, the current form is to be closed. To
streamline the process I have created code in a public module to open each
form:
Public Function DeptForm()
DoCmd.OpenForm "frmDept"
End Function
I call this in a command button's Click event (on the line in the property
sheet)
=DeptForm()
To close the current form I have another function in the public module:
Public Function CloseForm(frm as Form)
Dim strForm As String
strForm = frm.Name
DoCmd.Close acForm, strForm
End Function
I had thought I could call CloseForm from within DeptForm(), but if so I
can't find the syntax, or am doing something else wrong.
If I do:
Call CloseForm(frm)
I get Error 91, Object Variable or With Block Variable not set (or something
like that) when I compile the code. However, attempts to declare the
variable, either on the module level or within the DeptForm function, do not
improve the situation. The code seems to compile OK, but then I get Error
91 as a run-time error when I click the command button.
I can run both functions from the Click event line in the form's property
sheet:
=DeptForm()=CloseForm([Form])
I expect I could call both from the Click event VBA code, but that wouldn't
answer my main questions either, which are whether I am taking a generally
reasonable approach, and if so how best to make it work.
database. When the form is opened, the current form is to be closed. To
streamline the process I have created code in a public module to open each
form:
Public Function DeptForm()
DoCmd.OpenForm "frmDept"
End Function
I call this in a command button's Click event (on the line in the property
sheet)
=DeptForm()
To close the current form I have another function in the public module:
Public Function CloseForm(frm as Form)
Dim strForm As String
strForm = frm.Name
DoCmd.Close acForm, strForm
End Function
I had thought I could call CloseForm from within DeptForm(), but if so I
can't find the syntax, or am doing something else wrong.
If I do:
Call CloseForm(frm)
I get Error 91, Object Variable or With Block Variable not set (or something
like that) when I compile the code. However, attempts to declare the
variable, either on the module level or within the DeptForm function, do not
improve the situation. The code seems to compile OK, but then I get Error
91 as a run-time error when I click the command button.
I can run both functions from the Click event line in the form's property
sheet:
=DeptForm()=CloseForm([Form])
I expect I could call both from the Click event VBA code, but that wouldn't
answer my main questions either, which are whether I am taking a generally
reasonable approach, and if so how best to make it work.