Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting an Access application twice. 2

Status
Not open for further replies.

liamcorkhill

Programmer
Jul 3, 2001
18
GB
Hi all.

I have an Access application which I do not want users to be able to run more than once on a machine at any one time. Is there anyway of preventing an Access application from being loaded twice?

Any help would be appreciated.

Regards

Liam Corkhill
 
Well, you could force it to be opened in Exclusive mode. See help files on this subject for more details. Have fun! :eek:)

Alex Middleton
 
As far as I am aware, that will prevent other people from loading the database from elsewhere on the network. This is not what I want. I want a method of preventing a user from loading the application twice on one machine.

Regards

Liam Corkhill
 
I think you are right. I'm not sure how you would do this. Have fun! :eek:)

Alex Middleton
 
I believe if you created a table that stored the login time and userid when the logged in. Delete this information when they close the database. You could check this table on login - if their ID already existed exit the startup routine.
 
Hold it there nomus1: you're dealing with users here, so it's not so obvious that they will close the db in the way you expect. Furthermore: if the db is on a network, and the network connection fails the "lock" record also remains in the db
a way to actually do this is to make a workgroup file, provide every user with a logon name, and upon opening the database, checking if the user is already logged on to the workgroup file. I did not test in this exact way (i use it to count users that are logged in ) so it might need some minor adjustments:


Dim cn As New Connection
Dim rs As New Recordset
Dim var_user As Variant
Dim var_val As Variant
Dim str_db As String

str_db = CurrentDb
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & str_db

Set rs = cn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

Do While Not rs.EOF
var_val = rs.Fields(1).Value
If InStr(var_val, vbNullChar) > 0 Then 'eliminate NULLS in the string
var_val = Left(var_val, _
InStr(var_val, vbNullChar) - 1)
End If
var_user = var_val
If var_user = CurrentUser Then
MsgBox "too bad, get out !!"
'' handle kick-out
Exit Do
End If
rs.MoveNext
Loop


hope this does the trick

cpuburn
 
Interesting.

I tried copy - pasting that code into the Form Load method of my autoexec form. It didnt work :-(
Various methods (Open of Connection and OpenSchema of Connection) didnt seem to exist.
I have never messed about with the Connection object before so I dont really know how to debug it.

One thing that I wondered:-

Where did "{947bb102-5d43-11d1-bdbf-00c04fb92675}" come from?!?

Regards,

Liam Corkhill
 
This was my first attempt at offering any input to a discussion, and based on CPUBurn's response, I must not have done a good job. I appologize.

The way we have structured all of our databases is to specify a form that opens on startup. This is always the first form that opens. We do not allow our users to open the database using the shift key, so this form is always the first form a user sees. This form is minimized whenever another form is open and restored whenever the other form is closed. We also only allow the database to be closed using this form. (we do this by setting a public variable when the database is opened, and checking this variable when the startup form is closed - since this form is the first one that is opened, it is the last one that is closed)

By having a form like this you could create a table that stores the userid info. In the onload event add code to check to see if the currentuser() exists in the table. If so, give them an error message telling them they already have the database open, if it does not exist, add the information.

During the onclose event for this form delete the currentuser() id from the table.

I hope this is a better explanation of what I had in mind.
 
I have an app I built (originally in 2.0) that logs each user in a table on the BE. It records id, datein, dateout and PC_ID. I modified this so that if PC_ID, User_ID and dateout = "" any additional logon attempts would do an Application.Quit. This has been in use by me for a number of years and has worked through the migration to 97 and 2K.

I tried using a workgroup setup to prevent this and it not only limited the app on the PC it limited the user to one signon. No good.

Anyway, the way I used above has worked well and provides me with a user and machine log.
 
Thanks all for your responses. And dont worry nomus1, your feedback was much appreciated :).
The idea of creating a "lock" table had crossed my mind, however the reason I dont want the db opening twice is because I have a "server" which is basically a form running on a PC with an "On Timer" event to import files that our email system dumps in to a directory.

If the database is running twice, the two databases try and import the same file at the same time and the whole thing falls over.

Isnt it just my luck that our backup program has a bug in it where it sometimes re-loads my application twice :-(.

I cant have a login form because then someone would have to log in to the system at 1am every morning when the db restarts after backup.

The only way I can think of doing it is to mess about with API calls to see if Access is running twice on App start...but I dont know where to start with API!!

Ah well... Im sure something will come to me, it usually does!

Regards

Liam Corkhill
 
Woah! I wont ask where you dreamt that code up from, but it seems to work a treat!
Many thanks to all who replied to this thread! :)

Kind Regards,

Liam Corkhill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top