Results 1 to 5 of 5

Thread: Access Macros

  1. #1
    Star Lounger
    Join Date
    Jun 2005
    Location
    Delaware
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access Macros

    Hi, I am creating a database and I wanted to create a macro that would do the following. Whenever the user typed something in a textbox, I want the macro to validate the text typed and then open a form once validated. For example whenever the word michael is typed into the text box and the "submit" button is clicked it would open the form, but if something other than michael is typed a msgbox would open and say that the incorrect word was typed, please try again.
    Basically I want to use it as a password. So that only specific users could have access to this particular form.

    Thanks

  2. #2
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Macros

    Create a basic form, with a text box (txtPWord) and an command button (cmdEnter).

    Right click on your command button, and go to properties. On the event tab of the properties window, select the On Click event, and the click the little button "..." Choose Code Builder. Paste this code:

    Private Sub cmdEnter_Click()
    Select Case Me.txtPWord
    Case "Michael"
    DoCmd.OpenForm "MyForm"
    Case Else
    MsgBox "Please enter correct password"
    End Select

    End Sub

    Where MyForm = the name of your form. You can enter multiple options, by adding more Case statements, displayed below:

    Select Case Me.txtPWord
    Case "Michael"
    DoCmd.OpenForm "MyForm"
    Case "Jeremy"
    DoCmd.OpenForm "YourForm"
    Case "Jack"
    DoCmd.OpenForm "OurForm"
    Case Else
    MsgBox "Please enter correct password"
    End Select

    End Sub

    If you're using this for security purposes, you may wish to investigate user level security. Some good examples are posted here: the Access Experts: Custom Database Solutions
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What's more, you deserve to be hacked." -Richard Clarke

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access Macros

    You wouldn't do this with macros, assuming you are using the term in the sense it is used in Access. Even if you are talking about code, you would be better advised to implement Access security for this purpose. Moderator <!profile=WendellB>WendellB<!/profile> has an Access Security tutorial on his website at http://www.access-experts.com that might be of help to you.
    Charlotte

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Macros

    Welcome to Woody's Lounge!

    Designing your own security is a lot of work, and very difficult to make watertight. Access supports user-level security; this is much more robust than anything you could design yourself, and it allows you to specify permissions for each user for each individual database object. Moderator <!profile=WendellB>WendellB<!/profile> has a short tutorial on his website, with lots of useful links: The Secrets of Security.

  5. #5
    Star Lounger
    Join Date
    Jun 2005
    Location
    Delaware
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Macros

    Thanks. It works now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •