We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Restrict an Event Procedure from running

seamus99
seamus99 asked
on
Medium Priority
324 Views
Last Modified: 2012-05-11
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
   
'test
'    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
        .MoveFirst
        While Not .EOF
           
            str = .Fields("Hyperlink")
            ar = Split(str, "#")
            sFileFromHyperlink = ar(1)
            If FileExists(sFileFromHyperlink) Then
'            Debug.Print getFileFromHyperlink
                ammEmail.AddAttachment sFileFromHyperlink
            Else
'            Debug.Print "file missing"
            End If
            .MoveNext
        Wend
    End With
   
    ammMultiAttProcess.Execute
   
    Set ammEmail = Nothing
    Set ammMultiAttProcess = Nothing
    Set ammCurrentProcesses = Nothing
   
   
End Sub
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

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
getUserName=environ("userName")

end function

'other wise give deatials where to get the username


Author

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?
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.