473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Limiting users

Hi all,

Have written some code to limit the concurrent users of a database. Use the
Autoexec macro to open a form. When the form opens it increments a value in
a table. When the form closes (i.e. when the database closes, then the
number in the table is decremented. I plan to use this on a front/back end
setup, with a number of front end users on the network.

What i'm concerned about is if for some reason the network fails, and the
database crashes then the number will be one higher than it should, and this
could lead to a progressive problem. Thought of putting an error trap, but
don't this want to trigger and update if the error does not close the
database, as this would lead to the same problem .

Code is below.

Not looking for code, but advice on general solution or principles.
Thanks in advance.

CODE
----------------------------------------------------------------------------
--
Option Compare Database
Option Explicit
'This references a table called tblSysConstants, with fields Id, and Value.
'This constant must be set to the index number of the record holding the
users
'value in the tblSysConstants table
Const mNdx As Integer = 1

Const maxUsers As Integer = 3 'Set the max number of users
'
Function AddUser()
Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) + 1
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)
If iValue > maxUsers Then
MsgBox "Sorry but you have reached the limit of users"
Call RemoveUser ' remove the added user before exiting.
DoCmd.Quit
End If
End Function

Function RemoveUser()

Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) - 1
If iValue < 0 Then iValue = 0
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)

End Function
Public Function sysConstGet(ndx As Integer) As String
'returns the value in the Value field of tblSysConstants
'when the user arguament of the Id is supplied.
'table should have Id as key field

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset, dbReadOnly)

With rsSys

.MoveFirst

For i = 1 To .RecordCount
If !id = ndx Then
sysConstGet = Trim(!Value)
Else
.MoveNext
End If
Next i

End With

Set rsSys = Nothing
Set db = Nothing

End Function

Public Function SysConstPut(ndx As Integer, mValue As String)
'This put a user input value into the value field of a record
'in the tblSysConst table. Ndx is the record Id number, and
'mValue is the value to be placed in the 'Value field of this
'record

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)

With rsSys

..MoveFirst

..FindFirst !id = ndx
If Not .NoMatch Then
..Edit
!Value = mValue
..Update
Else
MsgBox "No record match"
End If
End With
Set rsSys = Nothing
Set db = Nothing
End Function
--------------------------------------------
--

Gerry
Mitas
Ryemont Abbey,
Leixlip,
Co. Kildare
Phone: 01 6104509
Fax:01 601 4716
In**@mitas.ie
www.mitas.ie
_______________

DISCLAIMER:
This e-mail may contain proprietary information,
and is covered by copyright. It may be legally privileged, and is for the
intended
recipient only. If you are not the intended recipient you must not use,
disclose, distribute, copy, print or rely on this e-mail.
Nov 12 '05 #1
6 1814
Make yourself a "back door" that you can use, that doesn't check the table,
but does allow you to reset it. Hide it cleverly, and don't forget how you
hid it!

Larry Linson
Microsoft Access MVP

"Gerry Abbott" <pl****@ask.ie> wrote in message
news:bN*******************@news.indigo.ie...
Hi all,

Have written some code to limit the concurrent users of a database. Use the Autoexec macro to open a form. When the form opens it increments a value in a table. When the form closes (i.e. when the database closes, then the
number in the table is decremented. I plan to use this on a front/back end
setup, with a number of front end users on the network.

What i'm concerned about is if for some reason the network fails, and the
database crashes then the number will be one higher than it should, and this could lead to a progressive problem. Thought of putting an error trap, but
don't this want to trigger and update if the error does not close the
database, as this would lead to the same problem .

Code is below.

Not looking for code, but advice on general solution or principles.
Thanks in advance.

CODE
-------------------------------------------------------------------------- -- --
Option Compare Database
Option Explicit
'This references a table called tblSysConstants, with fields Id, and Value. 'This constant must be set to the index number of the record holding the
users
'value in the tblSysConstants table
Const mNdx As Integer = 1

Const maxUsers As Integer = 3 'Set the max number of users
'
Function AddUser()
Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) + 1
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)
If iValue > maxUsers Then
MsgBox "Sorry but you have reached the limit of users"
Call RemoveUser ' remove the added user before exiting.
DoCmd.Quit
End If
End Function

Function RemoveUser()

Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) - 1
If iValue < 0 Then iValue = 0
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)

End Function
Public Function sysConstGet(ndx As Integer) As String
'returns the value in the Value field of tblSysConstants
'when the user arguament of the Id is supplied.
'table should have Id as key field

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset, dbReadOnly)

With rsSys

.MoveFirst

For i = 1 To .RecordCount
If !id = ndx Then
sysConstGet = Trim(!Value)
Else
.MoveNext
End If
Next i

End With

Set rsSys = Nothing
Set db = Nothing

End Function

Public Function SysConstPut(ndx As Integer, mValue As String)
'This put a user input value into the value field of a record
'in the tblSysConst table. Ndx is the record Id number, and
'mValue is the value to be placed in the 'Value field of this
'record

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)

With rsSys

.MoveFirst

.FindFirst !id = ndx
If Not .NoMatch Then
.Edit
!Value = mValue
.Update
Else
MsgBox "No record match"
End If
End With
Set rsSys = Nothing
Set db = Nothing
End Function
--------------------------------------------
--

Gerry
Mitas
Ryemont Abbey,
Leixlip,
Co. Kildare
Phone: 01 6104509
Fax:01 601 4716
In**@mitas.ie
www.mitas.ie
_______________

DISCLAIMER:
This e-mail may contain proprietary information,
and is covered by copyright. It may be legally privileged, and is for the
intended
recipient only. If you are not the intended recipient you must not use,
disclose, distribute, copy, print or rely on this e-mail.

Nov 12 '05 #2
Thanks Larry,
I use a back-door key to bypass shift, menus, and toolbars, etc, on some of
my applications. They work fine.

However don't think the problem associted with my approach is an 'access'
(literal) one. Am concerned that when I deploy to a client, then this
problem expresses itself, and there's no solution that I can give them,
short of allowing them to reset as you described, or me going in and
changing a value in the table manually.

I'm thinking is there a way to close all links to the back end file, then
reset the value. That way the client could have a reset button, which would
allow them to rectify the problem without my intervention.

However this may create more problems than it solves, un-hooking any open
front ends, The specific application I wish to implement this with is a
read only front end, so data corruption should not be an issue, if i
'kicked-out' any logged on users.

"Larry Linson" <bo*****@localhost.net> wrote in message
news:7p*******************@nwrddc03.gnilink.net...
Make yourself a "back door" that you can use, that doesn't check the table, but does allow you to reset it. Hide it cleverly, and don't forget how you
hid it!

Larry Linson
Microsoft Access MVP

"Gerry Abbott" <pl****@ask.ie> wrote in message
news:bN*******************@news.indigo.ie...
Hi all,

Have written some code to limit the concurrent users of a database. Use

the
Autoexec macro to open a form. When the form opens it increments a value

in
a table. When the form closes (i.e. when the database closes, then the
number in the table is decremented. I plan to use this on a front/back end setup, with a number of front end users on the network.

What i'm concerned about is if for some reason the network fails, and the database crashes then the number will be one higher than it should, and

this
could lead to a progressive problem. Thought of putting an error trap, but don't this want to trigger and update if the error does not close the
database, as this would lead to the same problem .

Code is below.

Not looking for code, but advice on general solution or principles.
Thanks in advance.

CODE


--------------------------------------------------------------------------
--
--
Option Compare Database
Option Explicit
'This references a table called tblSysConstants, with fields Id, and

Value.
'This constant must be set to the index number of the record holding the
users
'value in the tblSysConstants table
Const mNdx As Integer = 1

Const maxUsers As Integer = 3 'Set the max number of users
'
Function AddUser()
Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) + 1
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)
If iValue > maxUsers Then
MsgBox "Sorry but you have reached the limit of users"
Call RemoveUser ' remove the added user before exiting.
DoCmd.Quit
End If
End Function

Function RemoveUser()

Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) - 1
If iValue < 0 Then iValue = 0
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)

End Function
Public Function sysConstGet(ndx As Integer) As String
'returns the value in the Value field of tblSysConstants
'when the user arguament of the Id is supplied.
'table should have Id as key field

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset, dbReadOnly)
With rsSys

.MoveFirst

For i = 1 To .RecordCount
If !id = ndx Then
sysConstGet = Trim(!Value)
Else
.MoveNext
End If
Next i

End With

Set rsSys = Nothing
Set db = Nothing

End Function

Public Function SysConstPut(ndx As Integer, mValue As String)
'This put a user input value into the value field of a record
'in the tblSysConst table. Ndx is the record Id number, and
'mValue is the value to be placed in the 'Value field of this
'record

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)

With rsSys

.MoveFirst

.FindFirst !id = ndx
If Not .NoMatch Then
.Edit
!Value = mValue
.Update
Else
MsgBox "No record match"
End If
End With
Set rsSys = Nothing
Set db = Nothing
End Function
--------------------------------------------
--

Gerry
Mitas
Ryemont Abbey,
Leixlip,
Co. Kildare
Phone: 01 6104509
Fax:01 601 4716
In**@mitas.ie
www.mitas.ie
_______________

DISCLAIMER:
This e-mail may contain proprietary information,
and is covered by copyright. It may be legally privileged, and is for the intended
recipient only. If you are not the intended recipient you must not use,
disclose, distribute, copy, print or rely on this e-mail.


Nov 12 '05 #3
I've implemented a kick-out on an Access client to a server database for a
different purpose -- to allow the Adminstrator to force users off for
necessary maintenance.

I put a timer on a startup form, and in the Timer event, checked the table
in the back end -- if the DBA had put a maintenance warning, it warned the
user at specified intervals in advance, and then at the specified time, did
a DoCmd.Quit. If an attempt was made to restart the client during in a
maintenance period, the client front-end wouldn't start up... that was the
first check. You could do something similar from your backdoor front-end...
set the flag, kick the users off, fix the table, then clear the flag.

Larry Linson
Microsoft Access MVP
"Gerry Abbott" <pl****@ask.ie> wrote in message
news:ds*******************@news.indigo.ie...
Thanks Larry,
I use a back-door key to bypass shift, menus, and toolbars, etc, on some of my applications. They work fine.

However don't think the problem associted with my approach is an 'access'
(literal) one. Am concerned that when I deploy to a client, then this
problem expresses itself, and there's no solution that I can give them,
short of allowing them to reset as you described, or me going in and
changing a value in the table manually.

I'm thinking is there a way to close all links to the back end file, then
reset the value. That way the client could have a reset button, which would allow them to rectify the problem without my intervention.

However this may create more problems than it solves, un-hooking any open
front ends, The specific application I wish to implement this with is a
read only front end, so data corruption should not be an issue, if i
'kicked-out' any logged on users.

"Larry Linson" <bo*****@localhost.net> wrote in message
news:7p*******************@nwrddc03.gnilink.net...
Make yourself a "back door" that you can use, that doesn't check the

table,
but does allow you to reset it. Hide it cleverly, and don't forget how you
hid it!

Larry Linson
Microsoft Access MVP

"Gerry Abbott" <pl****@ask.ie> wrote in message
news:bN*******************@news.indigo.ie...
Hi all,

Have written some code to limit the concurrent users of a database. Use
the
Autoexec macro to open a form. When the form opens it increments a
value in
a table. When the form closes (i.e. when the database closes, then the
number in the table is decremented. I plan to use this on a front/back end setup, with a number of front end users on the network.

What i'm concerned about is if for some reason the network fails, and the database crashes then the number will be one higher than it should,
and this
could lead to a progressive problem. Thought of putting an error trap,

but don't this want to trigger and update if the error does not close the
database, as this would lead to the same problem .

Code is below.

Not looking for code, but advice on general solution or principles.
Thanks in advance.

CODE


--------------------------------------------------------------------------
--
--
Option Compare Database
Option Explicit
'This references a table called tblSysConstants, with fields Id, and

Value.
'This constant must be set to the index number of the record holding
the users
'value in the tblSysConstants table
Const mNdx As Integer = 1

Const maxUsers As Integer = 3 'Set the max number of users
'
Function AddUser()
Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) + 1
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)
If iValue > maxUsers Then
MsgBox "Sorry but you have reached the limit of users"
Call RemoveUser ' remove the added user before exiting.
DoCmd.Quit
End If
End Function

Function RemoveUser()

Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) - 1
If iValue < 0 Then iValue = 0
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)

End Function
Public Function sysConstGet(ndx As Integer) As String
'returns the value in the Value field of tblSysConstants
'when the user arguament of the Id is supplied.
'table should have Id as key field

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset,

dbReadOnly)
With rsSys

.MoveFirst

For i = 1 To .RecordCount
If !id = ndx Then
sysConstGet = Trim(!Value)
Else
.MoveNext
End If
Next i

End With

Set rsSys = Nothing
Set db = Nothing

End Function

Public Function SysConstPut(ndx As Integer, mValue As String)
'This put a user input value into the value field of a record
'in the tblSysConst table. Ndx is the record Id number, and
'mValue is the value to be placed in the 'Value field of this
'record

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)

With rsSys

.MoveFirst

.FindFirst !id = ndx
If Not .NoMatch Then
.Edit
!Value = mValue
.Update
Else
MsgBox "No record match"
End If
End With
Set rsSys = Nothing
Set db = Nothing
End Function
--------------------------------------------
--

Gerry
Mitas
Ryemont Abbey,
Leixlip,
Co. Kildare
Phone: 01 6104509
Fax:01 601 4716
In**@mitas.ie
www.mitas.ie
_______________

DISCLAIMER:
This e-mail may contain proprietary information,
and is covered by copyright. It may be legally privileged, and is for the intended
recipient only. If you are not the intended recipient you must not use, disclose, distribute, copy, print or rely on this e-mail.



Nov 12 '05 #4
Thanks again Larry,

Think this is moving in the right direction. Will think more about it in the
next couple of days. Will reply to the thread with conclusions or further
queries.

Regards,

Gerry Abbott

"Larry Linson" <bo*****@localhost.net> wrote in message
news:48*******************@nwrddc01.gnilink.net...
I've implemented a kick-out on an Access client to a server database for a
different purpose -- to allow the Adminstrator to force users off for
necessary maintenance.

I put a timer on a startup form, and in the Timer event, checked the table
in the back end -- if the DBA had put a maintenance warning, it warned the
user at specified intervals in advance, and then at the specified time, did a DoCmd.Quit. If an attempt was made to restart the client during in a
maintenance period, the client front-end wouldn't start up... that was the
first check. You could do something similar from your backdoor front-end... set the flag, kick the users off, fix the table, then clear the flag.

Larry Linson
Microsoft Access MVP
"Gerry Abbott" <pl****@ask.ie> wrote in message
news:ds*******************@news.indigo.ie...
Thanks Larry,
I use a back-door key to bypass shift, menus, and toolbars, etc, on some

of
my applications. They work fine.

However don't think the problem associted with my approach is an 'access'
(literal) one. Am concerned that when I deploy to a client, then this
problem expresses itself, and there's no solution that I can give them,
short of allowing them to reset as you described, or me going in and
changing a value in the table manually.

I'm thinking is there a way to close all links to the back end file, then reset the value. That way the client could have a reset button, which

would
allow them to rectify the problem without my intervention.

However this may create more problems than it solves, un-hooking any open front ends, The specific application I wish to implement this with is a
read only front end, so data corruption should not be an issue, if i
'kicked-out' any logged on users.

"Larry Linson" <bo*****@localhost.net> wrote in message
news:7p*******************@nwrddc03.gnilink.net...
Make yourself a "back door" that you can use, that doesn't check the

table,
but does allow you to reset it. Hide it cleverly, and don't forget how you hid it!

Larry Linson
Microsoft Access MVP

"Gerry Abbott" <pl****@ask.ie> wrote in message
news:bN*******************@news.indigo.ie...
> Hi all,
>
> Have written some code to limit the concurrent users of a database. Use the
> Autoexec macro to open a form. When the form opens it increments a value in
> a table. When the form closes (i.e. when the database closes, then the > number in the table is decremented. I plan to use this on a front/back end
> setup, with a number of front end users on the network.
>
> What i'm concerned about is if for some reason the network fails,
and
the
> database crashes then the number will be one higher than it should, and this
> could lead to a progressive problem. Thought of putting an error
trap, but
> don't this want to trigger and update if the error does not close
the > database, as this would lead to the same problem .
>
> Code is below.
>
> Not looking for code, but advice on general solution or principles.
>
>
> Thanks in advance.
>
>
>
> CODE


-------------------------------------------------------------------------- --
> --
> Option Compare Database
> Option Explicit
> 'This references a table called tblSysConstants, with fields Id, and
Value.
> 'This constant must be set to the index number of the record holding the > users
> 'value in the tblSysConstants table
> Const mNdx As Integer = 1
>
> Const maxUsers As Integer = 3 'Set the max number of users
>
>
> '
> Function AddUser()
> Dim iValue As Integer
> Dim sValue As String
>
> iValue = Val(sysConstGet(mNdx)) + 1
> sValue = Str(iValue)
> Call SysConstPut(mNdx, sValue)
> If iValue > maxUsers Then
> MsgBox "Sorry but you have reached the limit of users"
> Call RemoveUser ' remove the added user before exiting.
> DoCmd.Quit
> End If
> End Function
>
> Function RemoveUser()
>
> Dim iValue As Integer
> Dim sValue As String
>
> iValue = Val(sysConstGet(mNdx)) - 1
> If iValue < 0 Then iValue = 0
> sValue = Str(iValue)
> Call SysConstPut(mNdx, sValue)
>
> End Function
>
>
> Public Function sysConstGet(ndx As Integer) As String
> 'returns the value in the Value field of tblSysConstants
> 'when the user arguament of the Id is supplied.
> 'table should have Id as key field
>
> Dim db As DAO.Database
> Dim rsSys As DAO.Recordset
> Dim sInt As Integer
> Dim sValue As Integer
> Dim i As Integer
> Set db = CurrentDb
> Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset,

dbReadOnly)
>
> With rsSys
>
> .MoveFirst
>
> For i = 1 To .RecordCount
> If !id = ndx Then
> sysConstGet = Trim(!Value)
> Else
> .MoveNext
> End If
> Next i
>
> End With
>
> Set rsSys = Nothing
> Set db = Nothing
>
> End Function
>
> Public Function SysConstPut(ndx As Integer, mValue As String)
> 'This put a user input value into the value field of a record
> 'in the tblSysConst table. Ndx is the record Id number, and
> 'mValue is the value to be placed in the 'Value field of this
> 'record
>
> Dim db As DAO.Database
> Dim rsSys As DAO.Recordset
> Dim sInt As Integer
> Dim sValue As Integer
> Dim i As Integer
> Set db = CurrentDb
> Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)
>
> With rsSys
>
> .MoveFirst
>
> .FindFirst !id = ndx
> If Not .NoMatch Then
> .Edit
> !Value = mValue
> .Update
> Else
> MsgBox "No record match"
> End If
> End With
> Set rsSys = Nothing
> Set db = Nothing
>
>
> End Function
> --------------------------------------------
>
>
> --
>
> Gerry
>
>
> Mitas
> Ryemont Abbey,
> Leixlip,
> Co. Kildare
> Phone: 01 6104509
> Fax:01 601 4716
> In**@mitas.ie
> www.mitas.ie
> _______________
>
> DISCLAIMER:
> This e-mail may contain proprietary information,
> and is covered by copyright. It may be legally privileged, and is
for the
> intended
> recipient only. If you are not the intended recipient you must not

use, > disclose, distribute, copy, print or rely on this e-mail.
>
>



Nov 12 '05 #5
Gerry,
What I've done in some of my apps is the following. Maybe you can use it for your situation.

Maybe my explanation is a bit clumsy, but this still isn't my native language ;-)

Every user needs a different username.
Start application: Username (CurrentUser) is put in a table (just called 'tabUsers') in the backend.
The number of records in this table is checked and when exceeding licence then the application
stops.

Our problem:
When the database crashes then username is still in the database and has to be released,
because when the same user logs in the app stops with a message explaining that user x is already in
the database..
To release a username this user has to log in again using a macro. (commandline .... /x macroname)
This macro deletes the logged-in-user from the table TabUsers
After that the user can log in again the usual way.

Also the app always checks on opening some crucial forms if the CurrentUser() still is present in
tabUsers.
If not (someone else used the release-macro with this username?) the application quits.
Of course this 'security' can be broken, but until now it works satisfactory to me.
Main problem is how and where to hide the number of allowed concurrent users...

--
Hope this helps
Arno R
"Gerry Abbott" <pl****@ask.ie> schreef in bericht news:bN*******************@news.indigo.ie...
Hi all,

Have written some code to limit the concurrent users of a database. Use the
Autoexec macro to open a form. When the form opens it increments a value in
a table. When the form closes (i.e. when the database closes, then the
number in the table is decremented. I plan to use this on a front/back end
setup, with a number of front end users on the network.

What i'm concerned about is if for some reason the network fails, and the
database crashes then the number will be one higher than it should, and this
could lead to a progressive problem. Thought of putting an error trap, but
don't this want to trigger and update if the error does not close the
database, as this would lead to the same problem .

Code is below.

Not looking for code, but advice on general solution or principles.
Thanks in advance.

CODE
----------------------------------------------------------------------------
--
Option Compare Database
Option Explicit
'This references a table called tblSysConstants, with fields Id, and Value.
'This constant must be set to the index number of the record holding the
users
'value in the tblSysConstants table
Const mNdx As Integer = 1

Const maxUsers As Integer = 3 'Set the max number of users
'
Function AddUser()
Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) + 1
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)
If iValue > maxUsers Then
MsgBox "Sorry but you have reached the limit of users"
Call RemoveUser ' remove the added user before exiting.
DoCmd.Quit
End If
End Function

Function RemoveUser()

Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) - 1
If iValue < 0 Then iValue = 0
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)

End Function
Public Function sysConstGet(ndx As Integer) As String
'returns the value in the Value field of tblSysConstants
'when the user arguament of the Id is supplied.
'table should have Id as key field

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset, dbReadOnly)

With rsSys

.MoveFirst

For i = 1 To .RecordCount
If !id = ndx Then
sysConstGet = Trim(!Value)
Else
.MoveNext
End If
Next i

End With

Set rsSys = Nothing
Set db = Nothing

End Function

Public Function SysConstPut(ndx As Integer, mValue As String)
'This put a user input value into the value field of a record
'in the tblSysConst table. Ndx is the record Id number, and
'mValue is the value to be placed in the 'Value field of this
'record

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)

With rsSys

.MoveFirst

.FindFirst !id = ndx
If Not .NoMatch Then
.Edit
!Value = mValue
.Update
Else
MsgBox "No record match"
End If
End With
Set rsSys = Nothing
Set db = Nothing
End Function
--------------------------------------------
--

Gerry
Mitas
Ryemont Abbey,
Leixlip,
Co. Kildare
Phone: 01 6104509
Fax:01 601 4716
In**@mitas.ie
www.mitas.ie
_______________

DISCLAIMER:
This e-mail may contain proprietary information,
and is covered by copyright. It may be legally privileged, and is for the
intended
recipient only. If you are not the intended recipient you must not use,
disclose, distribute, copy, print or rely on this e-mail.



Nov 12 '05 #6
Write a application to attempt to delete the .LDB file for your database. If
it succeeds, then nobody has your application open you can then connect to
you user table and clear the user count.

"Gerry Abbott" <pl****@ask.ie> wrote in message
news:bN*******************@news.indigo.ie...
Hi all,

Have written some code to limit the concurrent users of a database. Use the Autoexec macro to open a form. When the form opens it increments a value in a table. When the form closes (i.e. when the database closes, then the
number in the table is decremented. I plan to use this on a front/back end
setup, with a number of front end users on the network.

What i'm concerned about is if for some reason the network fails, and the
database crashes then the number will be one higher than it should, and this could lead to a progressive problem. Thought of putting an error trap, but
don't this want to trigger and update if the error does not close the
database, as this would lead to the same problem .

Code is below.

Not looking for code, but advice on general solution or principles.
Thanks in advance.

CODE
-------------------------------------------------------------------------- -- --
Option Compare Database
Option Explicit
'This references a table called tblSysConstants, with fields Id, and Value. 'This constant must be set to the index number of the record holding the
users
'value in the tblSysConstants table
Const mNdx As Integer = 1

Const maxUsers As Integer = 3 'Set the max number of users
'
Function AddUser()
Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) + 1
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)
If iValue > maxUsers Then
MsgBox "Sorry but you have reached the limit of users"
Call RemoveUser ' remove the added user before exiting.
DoCmd.Quit
End If
End Function

Function RemoveUser()

Dim iValue As Integer
Dim sValue As String

iValue = Val(sysConstGet(mNdx)) - 1
If iValue < 0 Then iValue = 0
sValue = Str(iValue)
Call SysConstPut(mNdx, sValue)

End Function
Public Function sysConstGet(ndx As Integer) As String
'returns the value in the Value field of tblSysConstants
'when the user arguament of the Id is supplied.
'table should have Id as key field

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset, dbReadOnly)

With rsSys

.MoveFirst

For i = 1 To .RecordCount
If !id = ndx Then
sysConstGet = Trim(!Value)
Else
.MoveNext
End If
Next i

End With

Set rsSys = Nothing
Set db = Nothing

End Function

Public Function SysConstPut(ndx As Integer, mValue As String)
'This put a user input value into the value field of a record
'in the tblSysConst table. Ndx is the record Id number, and
'mValue is the value to be placed in the 'Value field of this
'record

Dim db As DAO.Database
Dim rsSys As DAO.Recordset
Dim sInt As Integer
Dim sValue As Integer
Dim i As Integer
Set db = CurrentDb
Set rsSys = db.OpenRecordset("tblSysConstants", dbOpenDynaset)

With rsSys

.MoveFirst

.FindFirst !id = ndx
If Not .NoMatch Then
.Edit
!Value = mValue
.Update
Else
MsgBox "No record match"
End If
End With
Set rsSys = Nothing
Set db = Nothing
End Function
--------------------------------------------
--

Gerry
Mitas
Ryemont Abbey,
Leixlip,
Co. Kildare
Phone: 01 6104509
Fax:01 601 4716
In**@mitas.ie
www.mitas.ie
_______________

DISCLAIMER:
This e-mail may contain proprietary information,
and is covered by copyright. It may be legally privileged, and is for the
intended
recipient only. If you are not the intended recipient you must not use,
disclose, distribute, copy, print or rely on this e-mail.

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jay Moore | last post by:
Greetings, all! I have a project for work, and I'm not sure how to efficiently do what I need to do. I'm hoping someone out there can help. Project is this: I'm creating a web-based...
4
by: Adam | last post by:
Greetings, I am creating a web application, which I will be selling licenses to be able to use it. So Customer Group A, could purchase 3 licenses, Customer Group B could purchase 30. With...
1
by: Daniel | last post by:
limiting access to files with asp.net is there any way i can make a file only accessible to certain users of my website? my files are to large to copy to a temp directory and they are of many...
3
by: B | last post by:
I know there are several ways to speed up combo boxes and form loading. Most of the solutions leave rowsource of the combo box blank and set the rowsource to a saved query or an SQL with a where...
5
by: randyelliott | last post by:
Good Day, I have a MS Access (Access 2000 now upgraded to 2003) database that tracks customer information. One function of this database is to create an encrypted license file for our software,...
2
by: Gerry Abbott | last post by:
Hi all, Im using an ubound form and recordsets for data update. Id like to trap invalid entries on this form. How can i limit the number of characters the user enters for a particular field. ? ...
1
by: Brian Adams | last post by:
I have a UserControl which draws using GDI+ on the top 40 pixels or so. Everything below that is available for users to place other controls on (like buttons, etc.) What I need to be able to do...
1
by: Technical | last post by:
Hi, I'm currently working on a webproject with ASP.NET 2.0, Visual Studio 2005, and SQL Server 2005 that allows users to search for and view images. My problems is that I need a way to limit...
2
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.