473,395 Members | 2,006 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.

Set the max number of users

Need some help please. Have this code and for some reason it is not
working correctly. I am not receiving errors, just the table is not
being populated at all. I have created the tbl and the frm and when I
open up the db, it is not recording the number of users. I am still
new to VBA and would appreciate some assistance. I am running Access
2003

Thanks,
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

Jun 4 '07 #1
1 2102
ARC
I'm not sure about the tblSysConstants, as I've never used it. But I'll
include a function I use in Access 97 that works, so hopefully it will work
in 03 as well. Basically, when a user is connected to an .mdb file, an .ldb
file is created. I looked into this file and found that it should contain
the name of the machines logged in. So I wrote a function that will count
the names in the .ldb file. Just pass the database name to it, such as
database.mdb, and it will look in database.ldb:

--------------------
Public Function NumUsers(DBName As String) As Integer
On Error GoTo ErrRtn
Dim UserName As String, UserRight As String, UserList As String
Dim ldbName As String
ldbName = Left(DBName, Len(DBName) - 4)
ldbName = Trim(ldbName & ".ldb")
NumUsers = 0
Open ldbName For Input Shared As #1
Do While Not EOF(1)
UserName = Input(31, #1)
NumUsers = NumUsers + 1
UserRight = Input(5, #1)
'if char = asc(32)
'Debug.Print Trim$(UserName)
UserList = UserList & Trim$(UserName) & ";"
Loop
'Debug.Print Chr(10) & Chr(13)
'Debug.Print "Number of users is: " & NumUsers
'Forms!fLoggedIn.lstUsers.RowSource = UserList
'Forms!fLoggedIn.Form!lblMsg.Caption = "Number Logged In: " & NumUsers
Close #1
'now find the number of users logged in through all add-ins and deduct them
from the total
Exit Function
ErrRtn:
NumUsers = 1
If err = 53 Then '.ldb file not found
'MsgBox "There are no user's in this .ldb file"
'Forms!fLoggedIn.Form!lstUsers.RowSource = ""
'Forms!fLoggedIn.Form!lstUsers.Requery
'Forms!fLoggedIn.Form!lblMsg.Caption = "Number Logged In: 0"
ElseIf err = 62 Then
Close #1
Exit Function
Else
MsgBox err.Number & " - " & err.Description & ", Function: NumUsers"
End If
End Function
Jun 6 '07 #2

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

Similar topics

7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
13
by: Ron | last post by:
Hi all I'm deciding whether to use the PK also as an account number, invoice number, transaction number, etc that the user will see for the respective files. I understand that sometimes a...
3
by: Rod | last post by:
Today and tomorrow we're demonstrating our ASP.NET application to the external business customers who will be using it (this is what would best be called a B2B application). I've set things up so...
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
2
by: Simon | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
2
by: mktselvan | last post by:
Hi, Existing running oracle application 11i (11.5.8) Database version is 8.1.7.4 There is any command / way to know the number of concurrent users for this application. ...
8
by: Mike P | last post by:
What would be the best way of counting the number of users who are currently logged on to a website? I am making the users login against a database of valid users. Would the best way be to add a...
5
by: Jonathan Wood | last post by:
Greetings, I'm using ASP.NET membership and I'd like to query the number of users in a particular role. I don't want the overhead of returning a dataset and then getting the number of items...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.