Restrict an Event Procedure from running

Posted on 2011-04-24
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
'    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
Question by:seamus99
    LVL 119

    Expert Comment

    by:Rey Obrero
    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


    Author Comment

    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?
    LVL 119

    Accepted Solution

    change this

    if getUserName="Eric" then exit sub


    if getUserName="Eric" then
       msgbox "Your message here
       exit sub
    end if

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now