Password Protect A Form

mark curtis

Registered User.
Local time
Today, 03:32
Joined
Oct 9, 2000
Messages
457
Dear all,

I have a form that loads up via an autoexec.
On that form all project records are visible and a user can load their project by selecting a cmd button on the record line for their project.

There are two things that I would love to do and I need help & example code if possible:

1)When a user creates a new project I want to be able to prompt the user to create a password for that project.

2)Any time the user wants to oprn their project via the aforementioned cmd button then they must enter the password.

I know that I can store the passwords in a USys... table and lock down the toolbars. But as far as creating the code for the above..well once again I am in the hands of the experts.

As always much appreciated.

Mark
 
When the user creates a project I assume you will have some table storing information about it. Particularly a uniquely identifying field. Have a table with this ID and the password the user inputs.
When the user tries to open the project next time, you check this table for the password. And force the user to enter that password.

You'll need a form requesting the password the first time. But you will also have to allow the user to create the project before i.e. the record, so you can get the ID value.

You could do this:
The user requests to start a new project. You create a new blank project in code.

Private Function CreateNewProject() as Integer
Dim rst as Recordset
Set rst = CurrentDb.Openrecordset("SELECT * FROM tblProjects")
rst.addnew
rst.update
rst.bookmark = rst.lastmodified
CreateNewProject = rst.ProjectID
rst.close
set rst = nothing
End Function

'command button on your record line you mentioned
Private Sub cmdbttnNewProject_Click()
intProjectID = CreateNewProject
docmd.openForm "frmGetPassword"
End Sub


So you have a function which creates the project record and returns its ID. When you are ready to collect information about the project simply find the record with that ID and update the record.

Prompt the user for a password.

'command button on the form whee you capture the users password
Private Sub cmdbttnOK_Click()
Dim rst as recordset
Set rst = Currentdb.openrecordset("SELECT * FROM tblProjectPasswords")
rst.addnew
rst!ProjectCODE = intProjectID 'remember this is the value you would have assigned before
'ProjectID = CreateNewPRoject()
rst!Password = me.txtPassword
rst.update
rst.close
Set rst = nothing
end sub

Now you are ready to collect you information about the project

'Command button on some form where you gather inormation about the project
Private Sub cmdbttnSaveNewProject()
Dim rst as Recordset
Set rst = CurrentDb.Openrecordset("SELECT * FROM tblProjects")
rst.findfirst "[ProjectID] =" & intProjectID
if rst.recordcount = 0 then
msgbox "PRoject Not Found"
Else
rst.edit
rst!ProjectName = me.txtProjectName
...
rst.update
End if
End Sub

There you have a table with the passwords, one with your project.

maybe some syntax errors in there. I'm just writing of the top of my head here.
Hope this helps you.

ntp
 

Users who are viewing this thread

Back
Top Bottom