?
Solved

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

Posted on 2000-03-10
6
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

762 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