button security

mkelly

Registered User.
Local time
Today, 14:17
Joined
Apr 10, 2002
Messages
213
If this is my button code:

Private Sub edit_info_form_Click()

On Error GoTo Err_edit_info_form_Click

Dim stDocName As String

stDocName = "@open edit information form"
DoCmd.RunMacro stDocName

Exit_edit_info_form_Click:
Exit Sub

Err_edit_info_form_Click:
MsgBox Err.Description
Resume Exit_edit_info_form_Click

End Sub

What code could I add and where so that a password was needed to open the form associated with the button?

Help greatly appriciated
 
Firstly, I would convert the macro "@open edit information form" into VBA code if possible - you can do this via the main menu bar (cannot remember the sequence though) and plug that code into your existing code.

Either way, you can use one of the following to allow access.


Code:
[b]simple way[/b]
.....

If inputbox("Please enter password") = "YourPassword" then
stDocName = "@open edit information form" 
DoCmd.RunMacro stDocName 
end if

or

Code:
[b]a little better[/b]
.....

If inputbox("Please enter password") = Dlookup("[Password]","tblFormAccess") then
stDocName = "@open edit information form" 
DoCmd.RunMacro stDocName 
end if
where Password is the name of the field and tblFormAccess is the name of the table.

Better again is to use the security built into access but this has its pitfalls. Also you could create a table with the formname, password and modify the dlookup to find the password for the form you are wanting to open.

Look to start using VBA rather than macros - it allows much more flexibility
 
Thanks, but noe for a reallt dumb question.

Where di I input this code?

If inputbox("Please enter password") = Dlookup("[Password]","tblFormAccess") then
stDocName = "@open edit information form"
DoCmd.RunMacro stDocName
end if
 
instead of this line

Code:
stDocName = "@open edit information form"
 

Users who are viewing this thread

Back
Top Bottom