Public Function closeform(NameOfForm, OpenThisForm As Variant)
'This function closes the current form and loads another
'You can define "code" words and add specialist actions in the case select
'other than that the Form named to be opened (if it is a real form name)
'will result in that form opened.
Dim CF_Result As Boolean
CF_Result = False
On Error GoTo Err
Select Case OpenThisForm 'select the open via nickname
Case "CJE"
DoCmd.OpenForm "Plus Clients and estimates"
If NameOfForm <> "Plus Clients and estimates" Then CF_Result = True
Case "Y" 'Add popups
DoCmd.OpenForm "Start-Up"
Case "CAL" 'Add other one off special actions
DoCmd.OpenReport "Calender01"
Case Else 'select to open via true name (better)
If NameOfForm <> OpenThisForm Then
DoCmd.OpenForm OpenThisForm
CF_Result = True
Else
CF_Result = False
End If
End Select
GoTo No_Error 'skip this old fasioned "goto" jumping
err2:
CF_Result = False
MsgBox "Error SB42.1: form can not be closed. " & Err.Number & " - " & Err.Description
GoTo Still_no_error 'get out of this and end the function
Err:
MsgBox "Failed to find " & OpenThisForm
CF_Result = False
No_Error:
On Error GoTo err2
If CF_Result <> False Then DoCmd.Close acForm, NameOfForm
Still_no_error:
closeform = CF_Result
End Function