If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > access: password protect a form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Dec 2002
Posts: 6
access: password protect a form

I'd like to password protect a form, but I do not want to set up user groups as this will be overkill for this database. The form is opened by a command button, and I think a macro can be used to prompt for a password before opening the form, but I do not know how to implement this!
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Apr 2002
Posts: 139
It is not a very secure way, but I use it sometimes when security is not a big issue, and I just want normal users to stay out of f.e. maintenance.

Make a dialog form with only one textfield (password) and Ok/Cancel button. If you set the input mask for the text field to "password", it will show only ******* when text is entered (see Access help for details).

On OK you will have to check the password the user entered with the required password, and if correct open your next form.

So you will have to store your required password somewhere in the database. Could be hardcoded in the dialog form, or stored in a table and called with f.e. DLookup. Again, not a very safe way, since tables are open to all. If it's hard coded in a form, an MDE will hide this.

hth
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Nov 2002
Location: Melbourne
Posts: 92
Private Sub Form_Open(Cancel As Integer)

Dim pwd As String
pwd = InputBox("What is the Password?")
If pwd = "TC" Then
MsgBox "You're In"
Else
MsgBox "Nice Try Wise Guy, You're Out!!"
DoCmd.Close
End If

End Sub


Place the Code in the OnOpen of the Form that you want to protect.

Change the wording too suit your needs.

Hope you find this useful
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Posts: 22
Password vs Expiration Date

Would using an expiration date and allowing full access rights to the DB be doable rather than using passwords? Most commerical software seems to protect applications not databases. Do you know of any software that allows database use for a defined number of days?

Thanks,

Bill

Boston, Massachusetts
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Oct 2002
Location: Leicester - UK
Posts: 820
you could try this if you're using a front end with the database window unavalable, create a table called DateValidation and on you main forms on open event do
Code:
Sub test()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("DateValidation")
    If rs.RecordCount = 0 Then
        rs.AddNew
        rs!deaddate = Date + 31
        rs.update
    ElseIf rs(1).Value < Date Then
        msgbox "this program has exceeded it 31 day trial period"
        DoCmd.Close
    End If
    
End Sub
now as long as you've disabled the ability for external access to the tables this shoul ddo the trick
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Oct 2003
Posts: 18
Is there a way of modifying this code to check that the user is a member of a specific group instead of prompting for a password ??

It sounds almost exaclty what i need.

Sorry for the newbie questions guys, i'm desperate !

thanks.. D

Quote:
Originally posted by billjov
Private Sub Form_Open(Cancel As Integer)

Dim pwd As String
pwd = InputBox("What is the Password?")
If pwd = "TC" Then
MsgBox "You're In"
Else
MsgBox "Nice Try Wise Guy, You're Out!!"
DoCmd.Close
End If

End Sub


Place the Code in the OnOpen of the Form that you want to protect.

Change the wording too suit your needs.

Hope you find this useful
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: Oct 2002
Location: Leicester - UK
Posts: 820
Quote:
Originally posted by thesponz
Is there a way of modifying this code to check that the user is a member of a specific group instead of prompting for a password ??

It sounds almost exaclty what i need.

Sorry for the newbie questions guys, i'm desperate !

thanks.. D
the answer is yes but how easy it is to do depends on a few things
1 where are you getting the username from
2 where are you getting the groups from

if both of these are stored in the database you've got the easy method but you still need to have them enter a password to confire the user name

if one or both of them are retreived from windows then you need to ask someone who's familiar with retieving windows enviroment variables which i have to say i'm not
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
Join Date: Oct 2003
Posts: 18
The User and the Group are set using the user level security built in to access.

For some reason i can't get this to stop people from opening certain forms so i thought that once they were logged in it would be easier to perform an OnOpen action to see who they were or better still which group.
Reply With Quote
  #9 (permalink)  
Old
Registered User
 
Join Date: Aug 2003
Location: SW Ohio
Posts: 198
I found this on the support.microsoft.com website way back when. It retrieves the username signed onto the WinXX box.

If you had a table that had the user names in that you want to allow access to the form then you could compare it with a table, or hard code users into the form.


' Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long

Const NoError = 0 'The Function call was successful

Public Function GetUserName()

' Buffer size for the return string.
Const lpnLength As Integer = 255

' Get return buffer space.
Dim status As Integer

' For getting user information.
Dim lpName, lpUserName As String

' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
Else

' An error occurred.
MsgBox "Unable to get the name."
End
End If

' Display the name of the person logged on to the machine.
'MsgBox "The person logged on this machine is: " & lpUserName
GetUserName = lpUserName

End Function
__________________
Jim P.

Supoorting Oracle, MSSQL7, Sybase 8, & Pervasive. Confusion Reigns
Reply With Quote
  #10 (permalink)  
Old
Registered User
 
Join Date: Nov 2003
Posts: 296
Cool How do I Mask what the user is typing?

GIven the code from the previous post:

How do I mask what the user is typing for a password with, a "*"??

THANKS!! IN ADVANCE

Private Sub Form_Open(Cancel As Integer)

Dim pwd As String
pwd = InputBox("What is the Password?")
If pwd = "TC" Then
MsgBox "You're In"
Else
MsgBox "Nice Try Wise Guy, You're Out!!"
DoCmd.Close
End If

End Sub
Reply With Quote
  #11 (permalink)  
Old
Cavalier King Charles
 
Join Date: Dec 2002
Location: Préverenges, Switzerland
Posts: 3,739
check out the properties of the text box: input mask -> password

izy
__________________
currently using SS 2008R2
Reply With Quote
  #12 (permalink)  
Old
Registered User
 
Join Date: Aug 2003
Location: SW Ohio
Posts: 198
Angry

You can't with an inputbox. You have to use a form and set the InputMask Property to Password on the textbox they are typing in.
__________________
Jim P.

Supoorting Oracle, MSSQL7, Sybase 8, & Pervasive. Confusion Reigns
Reply With Quote
  #13 (permalink)  
Old
Cavalier King Charles
 
Join Date: Dec 2002
Location: Préverenges, Switzerland
Posts: 3,739
too true!
i didn't read the earlier stuff talking about inputbox.



izy
__________________
currently using SS 2008R2
Reply With Quote
  #14 (permalink)  
Old
Registered User
 
Join Date: Nov 2003
Posts: 296
Help

You say it is--InputMask Property to Password
I am running Access 2000, How to I find this?
I am on the Properties of the FORM, but I do not see InputMask Property....

THANKS
Reply With Quote
  #15 (permalink)  
Old
Registered User
 
Join Date: Oct 2002
Location: Leicester - UK
Posts: 820
you don't want the form properties you want the properties of the object (normaly a textbox) that you intend the user to enter the password into
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On