Code:
Private Sub cmdAdmin_DblClick()
Dim strIDAdmin As String
Dim frmCurrentForm As Form
If Environ("USERNAME") <> "david.cromer" Then
msgbox ("You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions.")
Else
Set frmCurrentForm = Screen.ActiveForm
DoCmd.Close acForm, "frmCurrentForm", acSaveNo
DoCmd.OpenForm "frmAdminTools", acNormal, "", "", , acNormal
End If
End Sub
Regarding the code above.
There are two forms of message box. With parenthesis and with out parenthesis.
With parenthesis: returns an Integer indicating which button the user clicked to a variable.
With out parenthesis: displays a dialog box, waits for a button click, then closes.
Another indication is that the keyword "Msgbox" did not capitalize itself. If you type a line with a keyword in lower case, you move to a different line and the command automatically capitalizes itself, that has valid syntax.
You should have: (NO parenthesis)
Code:
msgbox "You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions."
You create a variable as a FORM, "frmCurrentForm", set it to the active form, then try to close it.
The command "Close" is looking for the NAME (as a text string) of the form, not an object of type form!!
Modified code
Code:
Private Sub cmdAdmin_DblClick()
' Dim strIDAdmin As String '<<unused - commented out
Dim frmCurrentForm As String '<< changed to a string
If Environ("USERNAME") <> "david.cromer" Then
'removed parenthesis
MsgBox "You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions."
Else
frmCurrentForm = Screen.ActiveForm.Name 'deleted "SET" from this line
DoCmd.Close acForm, frmCurrentForm '<< removed quotes & corrected syntax
DoCmd.OpenForm "frmAdminTools", acNormal '<<corrected syntax
End If
End Sub