Solved

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

Posted on 2000-03-10
6
300 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

914 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

18 Experts available now in Live!

Get 1:1 Help Now