473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to program command button in Access Macro to require a password

20
I created a simple macro to open a form with several command buttons on the form. On one of these buttons I want to require a password for access. I am not a programmer. What do I need to do to make this happen?

Thanks for your help
Oct 21 '10 #1

✓ answered by Rixxe

You really should google in the first instance, as many of the answers you want are avaliable.

None the less:

Open the switchboard form in design view and select the command button.
Select the On Click event and choose Event Procedure from the drop down list. Click on the ellipses (...) to enter the code window.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOpenEmpForm_Click()
  2.  
  3. 'Attached to On Click event of cmdOpenEmpForm
  4.  
  5.     Dim strPasswd
  6.  
  7.     strPasswd = InputBox("Enter Password", "Restricted Form")
  8.  
  9.     'Check to see if there is any entry made to input box, or if
  10.     'cancel button is pressed. If no entry made then exit sub.
  11.  
  12.     If strPasswd = "" Or strPasswd = Empty Then
  13.         MsgBox "No Input Provided", vbInformation, "Required Data"
  14.         Exit Sub
  15.     End If
  16.  
  17.     'If correct password is entered open Employees form
  18.     'If incorrect password entered give message and exit sub
  19.  
  20.     If strPasswd = "Graham" Then
  21.         DoCmd.OpenForm "frmEmp", acNormal
  22.     Else
  23.         MsgBox "Sorry, you do not have access to this form", _
  24.                vbOKOnly, "Important Information"
  25.         Exit Sub
  26.     End If
  27. End Sub
  28.  
You will notice the line If strPasswd = "Graham" Then . This contains the required password that will be required when attempting to open the form.

This can be changed to any password that you wish.


(Note: This information is originally from, and can be found at: http://www.databasedev.co.uk/button_security.html)

3 7843
Rixxe
7
You really should google in the first instance, as many of the answers you want are avaliable.

None the less:

Open the switchboard form in design view and select the command button.
Select the On Click event and choose Event Procedure from the drop down list. Click on the ellipses (...) to enter the code window.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOpenEmpForm_Click()
  2.  
  3. 'Attached to On Click event of cmdOpenEmpForm
  4.  
  5.     Dim strPasswd
  6.  
  7.     strPasswd = InputBox("Enter Password", "Restricted Form")
  8.  
  9.     'Check to see if there is any entry made to input box, or if
  10.     'cancel button is pressed. If no entry made then exit sub.
  11.  
  12.     If strPasswd = "" Or strPasswd = Empty Then
  13.         MsgBox "No Input Provided", vbInformation, "Required Data"
  14.         Exit Sub
  15.     End If
  16.  
  17.     'If correct password is entered open Employees form
  18.     'If incorrect password entered give message and exit sub
  19.  
  20.     If strPasswd = "Graham" Then
  21.         DoCmd.OpenForm "frmEmp", acNormal
  22.     Else
  23.         MsgBox "Sorry, you do not have access to this form", _
  24.                vbOKOnly, "Important Information"
  25.         Exit Sub
  26.     End If
  27. End Sub
  28.  
You will notice the line If strPasswd = "Graham" Then . This contains the required password that will be required when attempting to open the form.

This can be changed to any password that you wish.


(Note: This information is originally from, and can be found at: http://www.databasedev.co.uk/button_security.html)
Oct 21 '10 #2
cambar
20
Thanks very much. Worked great.
Oct 21 '10 #3
Rixxe
7
You're welcome.
Oct 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jason L. | last post by:
Here's the scenario. Using a campaigning applicaion for an eNewsletter. It writes to an Access table. I have an ASP web page that writes to another table. I chained 3 Access queries together into...
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
2
by: Darren | last post by:
Hi, I have a command button which has a macro running in it. The macro on the click event, runs to ensure that certain values in a form are valid, (e.g. the textboxes are not null) and...
4
by: Alex Chun | last post by:
How can I program a command button on a form to bring up the standard "Find and Replace" dialog on click? Separate but related: how do you run menu commands (e.g. "Edit" "Find") from VB? ...
2
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report...
1
by: yello | last post by:
Hi All, I have a MS Access macro which needs to be scheduled in the Task Scheduler. I am using the following link to schedule the macro "C:\Program Files\Microsoft...
0
by: sclinkenbeard | last post by:
I want to use a command button in Excel and have the VBA macro to open a PDF document. Does anyone know the VBA code to do so? It is easy opening word doc and another excel program but not sure how...
4
by: mld01s | last post by:
Hi all!! I need help, I have been stuck for a few days on this one. I am trying to open an excel table from a command button in Access. The excel table has an auto_open macro, that is supposed to...
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.