Hello,
I am not sure why this code is not working. I have a pop-form to edit a drop down list that is found in a control (combo box) on 8 different forms.
On this pop-up form, I have added a "Done" command button. When this button is clicked, I want to requery the control (combo box) on whichever main form is open so that the drop down list includes any edits or new entries that were made on the pop-up form.
I have created a conditional code (If, ElseIf, Else, End If) that looks to see which of the 8 forms is loaded, captures the open form name as a variable, "stForm", and then requeries the control on that form.
Form(stForm).cb oAddr2TypeLKUP. Requery
The problem that I am having is that the code only checks the first condition. After the If condition, it jumps to End If rather than cycling through the rest of the ElseIf conditions. What it means is that when the If condition is false, you get an error message: "The expression you entered refers to an object that is closed or doesn't exist."
When debugging the code, it shows stForm is equal to the form name in the If condition - even if that condition is false (that form is not open).
I cannot figure out why this is happening. Below is the code. Any advice/suggestions would be greatly appreciated.
Banderson
I am not sure why this code is not working. I have a pop-form to edit a drop down list that is found in a control (combo box) on 8 different forms.
On this pop-up form, I have added a "Done" command button. When this button is clicked, I want to requery the control (combo box) on whichever main form is open so that the drop down list includes any edits or new entries that were made on the pop-up form.
I have created a conditional code (If, ElseIf, Else, End If) that looks to see which of the 8 forms is loaded, captures the open form name as a variable, "stForm", and then requeries the control on that form.
Form(stForm).cb oAddr2TypeLKUP. Requery
The problem that I am having is that the code only checks the first condition. After the If condition, it jumps to End If rather than cycling through the rest of the ElseIf conditions. What it means is that when the If condition is false, you get an error message: "The expression you entered refers to an object that is closed or doesn't exist."
When debugging the code, it shows stForm is equal to the form name in the If condition - even if that condition is false (that form is not open).
I cannot figure out why this is happening. Below is the code. Any advice/suggestions would be greatly appreciated.
Banderson
Code:
Private Sub btnDone_Click()
On Error GoTo Err_btnDone_Click
Dim stForm As String
If CurrentProject.AllForms("frmSiteAdd").IsLoaded = True Then
stForm = "frmSiteAdd"
ElseIf CurrentProject.AllForms("frmSiteBasicsEdit").IsLoaded = True Then
stForm = "frmSiteBasicsEdit"
ElseIf CurrentProject.AllForms("frmContactAdd").IsLoaded = True Then
stForm = "frmContactAdd"
ElseIf CurrentProject.AllForms("frmContactBasicsEdit").IsLoaded = True Then
stForm = "frmContactBasicsEdit"
ElseIf CurrentProject.AllForms("frmStaffAdd").IsLoaded = True Then
stForm = "frmStaffAdd"
ElseIf CurrentProject.AllForms("frmStaffEdit").IsLoaded = True Then
stForm = "frmStaffEdit"
ElseIf CurrentProject.AllForms("frmBMCAdd").IsLoaded = True Then
stForm = "frmBMCAdd"
ElseIf CurrentProject.AllForms("frmBMCEdit").IsLoaded = True Then
stForm = "frmBMCEdit"
Else
stForm = ""
End If
DoCmd.Close
Form(stForm).cboAddr2TypeLKUP.Requery
Exit_btnDone_Click:
Exit Sub
Err_btnDone_Click:
MsgBox Err.Description
Resume Exit_btnDone_Click
End Sub
Comment