Solved

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

Posted on 2000-03-10
6
305 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Top 1 of each supplier 55 56
Access query expression 6 20
Archiving Access table older than 6 months 9 39
SQL Group on First occurrence 9 24
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

770 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