Restrict an Event Procedure from running

I have the following event procedure that gets invoked by cmdTestMulti_click().  I want to restrict a user from executing the command. Rather than creating a different version of my FE Database, I would like to check the username of the person trying to push the button, and if it equals "Eric" then display an information message stating he doesn't have the authority to process the claim.  

Private Sub cmdTestMulti_Click()
Dim ammCurrentProcesses As accessmailmerge.CurrentProcesses
Dim ammMultiAttProcess As accessmailmerge.Process
Dim ammEmail As accessmailmerge.SendMail
Dim ammMailMerge As accessmailmerge.MailMerge
Dim ar()  As String
Dim i As Integer
Dim rst As Recordset
Dim str As String
Dim sFileFromHyperlink As String
    Set ammCurrentProcesses = New accessmailmerge.CurrentProcesses
    Set ammMultiAttProcess = ammCurrentProcesses.Processes("Email with file attachment(s) 5") '5 works on the correct form
    Set ammMailMerge = ammMultiAttProcess.Activities(1) 'first activity is making the email body
    Set ammEmail = ammMultiAttProcess.Activities(2) 'second activity is the email
'    ammMultiAttProcess.ProcessRecords = mmpProcessCurrentRecord 'only one for testing
'    ammMailMerge.Template = "\\Beta\agora\Klanten\LARMSV\Templates\Email.htm" 'because not on machine at 4tops

    Set rst = Me!FinalReports.Form.RecordsetClone
    With rst
        While Not .EOF
            str = .Fields("Hyperlink")
            ar = Split(str, "#")
            sFileFromHyperlink = ar(1)
            If FileExists(sFileFromHyperlink) Then
'            Debug.Print getFileFromHyperlink
                ammEmail.AddAttachment sFileFromHyperlink
'            Debug.Print "file missing"
            End If
    End With
    Set ammEmail = Nothing
    Set ammMultiAttProcess = Nothing
    Set ammCurrentProcesses = Nothing
End Sub
Who is Participating?
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
change this

if getUserName="Eric" then exit sub


if getUserName="Eric" then
   msgbox "Your message here
   exit sub
end if
Rey Obrero (Capricorn1)Commented:
just insert a routine to check for the user name

Private Sub cmdTestMulti_Click()

if getUserName="Eric" then exit sub

'codes here

end sub

place this function in the form's module or in a regular module

function getUserName() as string
'if you want the login user name

end function

'other wise give deatials where to get the username

seamus99Author Commented:
In addition to not allowing the procdure to run, is there a way to display an informational message back to the sreen to tell the user he is not authorized?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.