Results 1 to 11 of 11
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    Password a form

    Hi



    been trying to use VBA to password a form and found the code below.

    typed it in manually and had errors, Then copied and pasted the code into the onload event in the vba window and got the same errors

    "The expression may not result in the name of a macro, the name of a user defined function or event procedure"

    There may have been an error in evaluating the function, event or macro

    I searched the web and found the suggestion to use the compile option in the VBA window which I did and got the error below

    "Invalid Outside procedure!"

    Code:
    Private Sub Form_Load()
    Dim PassWord As String
    PassWord = InputBox(“Enter Administrator Password”)
    If PassWord = “admin1234” Then
    ‘ Open Form
    DoCmd.OpenForm “frmAddRecord”
    DoCmd.GoToRecord , , acNewRec
    Else
    MsgBox (“You’re not authorized for Administrator access.”)
    End If
    End Sub
    I do realise it's probably not terribly secure but it's really only to stop accidental changes rather than a determined attack

    Would as usual appreciate any pointers

    Thanks

    Ian

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Try changing
    MsgBox (“You’re not authorized for Administrator access.”)

    to
    MsgBox "You’re not authorized for Administrator access."

    EDIT: Also, it seems you may have smart quotes pasted into your VBA Editor. Erase the double quotations and replace them by typing in another double quote.

  3. #3
    Jen0dorf is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    thanks for the hints

    regrettably it did not solve the issue

    off to research

    cheers

    Ian

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You might be asking Access to do something it cannot do while the form is still loading. Not sure what the form is about, but you might be able to run your code using an event other than the OnLoad event. Maybe On Current is suitable or use a command button or ...

  5. #5
    Jen0dorf is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    HI

    thanks, the research is continuing

    Ian

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Ian,

    I recommend using he form's On Open event to ask for the password.

    Here is a better way to handle what you want to do: https://support.microsoft.com/en-us/kb/209871


  7. #7
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Ian,

    If the form is only to be used by certain users then what I like to do is in the form's On Open event check the logged on user name, like the Windows User Name, to look up in a table to see if they have permission to use the form.

  8. #8
    Jen0dorf is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    thanks thats what I need

    cheers

    Ian

  9. #9
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by Jen0dorf View Post
    Hi

    thanks thats what I need

    cheers

    Ian

    Ian,

    You're welcome.

    May you have great success with your project.

  10. #10
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    you could always split the database and issue a front end that just allows them to change what you want.

  11. #11
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by Homegrownandy View Post
    you could always split the database and issue a front end that just allows them to change what you want.
    Great point.

    I often use multiple front ends to separate out "admin" functions for "data entry" functions.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-10-2014, 12:50 PM
  2. Replies: 2
    Last Post: 12-24-2012, 10:15 PM
  3. Replies: 1
    Last Post: 07-24-2012, 06:10 PM
  4. Replies: 1
    Last Post: 06-22-2012, 08:05 AM
  5. Password Form
    By hitesh_asrani_j in forum Forms
    Replies: 1
    Last Post: 09-26-2011, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums