so, i was just reviewing some of the most recent changes i've made to my DB here at work, and when i reached this piece of code, i started wondering if there's an easier, more compact way to do this. don't get me wrong, the code definitely works, and works well enough, i'm just curious for education's sake if there is a better way to go about this with less code involved? i feel like there should be a simpler way to test if any forms are open, rather than checking for each one individually.
Code:
If CurrentProject.AllForms("Resident_Automobile_Info").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
ElseIf CurrentProject.AllForms("Resident_Contact_Info").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
ElseIf CurrentProject.AllForms("Resident_Extra_Info").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
ElseIf CurrentProject.AllForms("Resident_General_Info").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
ElseIf CurrentProject.AllForms("Resident_Social_Sec_Info").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
ElseIf CurrentProject.AllForms("Resident_Status_Info").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
ElseIf CurrentProject.AllForms("Services_&_Amenities").IsLoaded Then
MsgBox "Updating tables is not recommended while Data Entry form(s) are open." & vbCrLf & "Please close any open Data Entry forms and try again.", vbCritical
Else
DoCmd.SetWarnings False
DoCmd.OpenQuery "UPDATE_RES_INFO_TABLE", acViewNormal, acEdit
DoCmd.OpenQuery "UPDATE_RESIDENT_STATUS_TABLE", acViewNormal, acEdit
DoCmd.OpenQuery "UPDATE_EMER_INFO_TABLE", acViewNormal, acEdit
DoCmd.OpenQuery "UPDATE_SOCIAL_SEC_INFO_TABLE", acViewNormal, acEdit
DoCmd.OpenQuery "UPDATE_AUTO_INFO_TABLE", acViewNormal, acEdit
DoCmd.SetWarnings True
MsgBox "Local tables updated.", vbInformation
End If