Solved

Mutiple User Database - restrict access screen - 1 user at a time

Posted on 2000-03-10
6
299 Views
Last Modified: 2008-03-17
Hi there

Have multiple - user db - 10 users at any time.  One of the screen only 1 person can use it at any time.

Question - is there a mechanism where

i).Restrict use of screen 1 user - lock others out.
2).If you are locked out - able to tell who is using the screen ??

Is it possible and how you do it - any ideas ????

Thanks.


0
Comment
Question by:ImraneA
6 Comments
 

Expert Comment

by:dramaqueen
ID: 2605197
Not sure why you'd want to lock users out of a form if someone else is using it. Access will by default lock a RECORD, preventing two users from editing the same data simultaneously, but not a form.

If you really did want to stop two people accessing the same form then you could do something like this:

1. Have a table (eg "frmUsers") containing a field for each form that you might want to protect.

2. Edit the code for the button that will open the form so that it checks to see if the appropriate field in "frmUsers" contains the name of the person using it. If the field is empty then open the form. If the field is not empty display a MsgBox telling the user that "<contents of field> is currently looking at this form" and do not open the form.

3. When (if) the form opens, set the name in the table to the user's name. (This could be stored elsewhere (say) in the client front end, or, if you're really clever you could get the user's network login id - I'm sure someone here could tell you how to do that... I couldn't)

4. When the user closes the form, the appropriate field in "frmUsers" must be set to "".

Ok, techie boys and girls - now turn it into proper code!
0
 
LVL 10

Accepted Solution

by:
paasky earned 50 total points
ID: 2605262
Hello,

Good suggestion dramaqueen !

As requested here's little coding help (should be placed into form which is needed to be locked by single user):

Private Sub Form_Close()
    ' Release form lock
    CurrentDb.Execute ("UPDATE tblFormLock SET UserName='' WHERE FormName = " & Chr(34) & Me.Name & Chr(34))
End Sub

Private Sub Form_Open(Cancel As Integer)
Dim StrUserName As String
       
    StrUserName = Nz(DLookup("UserName", "tblFormLock", "FormName=" & Chr(34) & Me.Name & Chr(34)), "")
   
    If StrUserName <> "" Then
        ' form is currently opened by another user
        MsgBox "Can't open form because it's locked by user " & StrUserName & "."
        Cancel = True
    Else
        ' form can be opened, lock the form
        CurrentDb.Execute ("UPDATE tblFormLock SET UserName=" & Chr(34) & CurrentUser() & Chr(34) & " WHERE FormName = " & Chr(34) & Me.Name & Chr(34))
    End If
End Sub

Table which contains locking information is named "tblFormLock" and it contains the following fields:

FormName (text) PrimaryKey
Username (text)

Regards,
Paasky
0
 
LVL 10

Expert Comment

by:paasky
ID: 2605287
ImraneA, forgot to mention that you need to populate table tblFormLock with the form name(s). If you have many forms to add, you can use this SQL to fill the table easily:

INSERT INTO tblFormLock ( FormName )
SELECT MSysObjects.Name
FROM MSysObjects
WHERE MSysObjects.Type=-32768;

Paasky
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:BrianWren
ID: 2606130
CurrentDb.Execute ("UPDATE tblFormLock SET . . . . .

Clever.  I'll remember that one.
0
 

Author Comment

by:ImraneA
ID: 2619116
Spot on but, had to use recordset (i.e. .edit & .update) rather CurrentDb.Execute ("UPDATE tblFormLock  etc.. for close event.

To improve robustness of this .
0
 
LVL 10

Expert Comment

by:paasky
ID: 2619377
Happy to help you ImraneA.

dramaqueen,
I think you deserve half of the points, because the idea came from you. I've posted a question for you (Q.10311249).

Regards,
Paasky
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now