Adjud
02-20-2014, 07:38 AM
Hello,
I have an excel document setup for a user to input information into, when the user opens the document, a userform covers the excel document (this is where the information is to be submitted) when the user is finished with said document this person will close the userform, on this happening the userform is to close the document as well.
while this has been acheived, i want it to have a fail safe, so incase i need to edit or view the information stored inside of the document, i want to have a key press tell the program that the user is either an admin or not when closing the userform, if they are an admin the userform closes and the document stays open for editing, if not then it all closes.
Thanks for any help!
This is what i have come up with so far, it seems to just close everything no matter what i pressed... so i removed the Application.Quit function to keep my document from being in an endless loop.
Dim Admin As Integer
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Application.OnKey "~", "Admin = 1"
End Sub
Private Sub userform_terminate()
If Admin > 0 Then
MsgBox "Welcome Admin"
Stop
Else
MsgBox "You are not Worthy"
ActiveWorkbook.Save
'Application.Quit
End If
End Sub
I have an excel document setup for a user to input information into, when the user opens the document, a userform covers the excel document (this is where the information is to be submitted) when the user is finished with said document this person will close the userform, on this happening the userform is to close the document as well.
while this has been acheived, i want it to have a fail safe, so incase i need to edit or view the information stored inside of the document, i want to have a key press tell the program that the user is either an admin or not when closing the userform, if they are an admin the userform closes and the document stays open for editing, if not then it all closes.
Thanks for any help!
This is what i have come up with so far, it seems to just close everything no matter what i pressed... so i removed the Application.Quit function to keep my document from being in an endless loop.
Dim Admin As Integer
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Application.OnKey "~", "Admin = 1"
End Sub
Private Sub userform_terminate()
If Admin > 0 Then
MsgBox "Welcome Admin"
Stop
Else
MsgBox "You are not Worthy"
ActiveWorkbook.Save
'Application.Quit
End If
End Sub