Help with code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I have downloaded a form that shows who is logged on, however it only shows
one person as being logged on (me) when I know that several other people are
also logged on.. The code attached to the form is as below:--


Option Compare Database 'Use database order for string comparisons
Private Sub Form_Open(Cancel As Integer)
Me.LoggedOn.RowSource = WhosOn()
End Sub

Private Sub OKBtn_Click()
DoCmd.Close A_FORM, "LoggedOn"
End Sub

Private Sub UpdateBtn_Click()
Me.LoggedOn.RowSource = WhosOn()
End Sub

Is there a way to make this list everyone within the data base, or does
anyone have a good program/ form that does this ???
 
Hi, Sam.
I have downloaded a form that shows who is logged on, however it only shows
one person as being logged on (me)

You haven't shown the code for the WhosOn() procedure, but I suspect that it
is merely the CurrentUser method returning the current user, you. The form
that you have downloaded contains deprecated code, circa VBA 4.0 (VB 3.0 --
about ten years ago).

Instead of using this ancient form, I would suggest either using the LDB
Viewer to view all the users who are logged on, or using the code on the
following Web page as a basis to create your own form to display the users
who are logged on:

http://support.microsoft.com/default.aspx?id=285822

You may find a link to Microsoft's free LDB Viewer and other free diagnostic
tools
in the "Free Microsoft Access Troubleshooting Tools" section on this Web page:

http://www.Access.QBuilt.com/html/links.html

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
The WhosOn() code was originally created by Mark Nally for Access 2.0, but
it is still perfectly valid (even though it is ancient). The problem is you
are looking at the LDB file for the front end, rather than for the back end
database. To view the LDB file for the back end, you have to supply the
database name of a linked table.

The offending section of code is this:
Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sUserList = ""
vTempList = GetUserList(dbCurrent.Name, sUserList)

You need to send the file name (with the entire path) to the GetUserList
function.

One way to do this is with ADO:
'********************************
Function FindSource() As String
'this function finds the Connect string of the first
'linked table in the hidden 'MSysObjects' table. It then
'returns just the path & filename. Note: this assumes all
'of the linked tables are in the same file. If this is not
'true, you can replace the DFirst function with the name of
'a specific linked table.

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim strLinkedTable As String
cat.ActiveConnection = CurrentProject.Connection

Dim txtLinkedTable As String
txtLinkedTable = DFirst("Name", "MSysObjects", "[Type] = 6")
'MsgBox txtLinkedTable

Set tbl = cat.Tables(txtLinkedTable)
'MsgBox tbl.Properties("jet OLEDB:Link Datasource")
FindSource = tbl.Properties("jet OLEDB:Link Datasource")

End Function
'********************************

Then you can supply the back-end database file name like this:
vTempList = GetUserList(FindSource(), sUserList)


Note: for reference the WhosOn code is listed below:

'*************************************************
Option Compare Database
Option Explicit

'Originally written for Access 2 by Mark Nally
'Revised an updated for Access 97 by:

'

Private Type UserRec
bMach(1 To 32) As Byte ' 1st 32 bytes hold machine name
bUser(1 To 32) As Byte ' 2nd 32 bytes hold user name
End Type

Private Sub Form_Open(Cancel As Integer)

Me.LoggedOn.RowSource = WhosOn()

End Sub



Private Sub OKBtn_Click()

DoCmd.Close A_FORM, "frmLoggedOn"

End Sub

Private Sub UpdateBtn_Click()

Me.LoggedOn.RowSource = WhosOn()

End Sub


'-----------------------------------------------------------------
' Subject : WhosOn()
' Purpose : Will read *.LDB file and read who's currently
' logged on and their station name.
'
' The LDB file has a 64 byte record.
'
' The station name starts at byte 1 and is null
' terminated.
'
' Log-in names start at the 33rd byte and are
' also null terminated.
'
' I had to change the way the file was accessed
' because the Input() function did not return
' nulls, so there was no way to see where the
' names ended.
'---------------------------------------------------------------------------
----------
Private Function WhosOn() As String

On Error GoTo Err_WhosOn

Dim dbCurrent As DAO.Database
Dim sUserList As String, vTempList As Variant

' Get Path of current database
' and for an attached table path in a multi-user environment.

Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sUserList = ""
vTempList = GetUserList(dbCurrent.Name, sUserList)
If Not IsNull(vTempList) Then
sUserList = vTempList
vTempList = GetUserList(Forms!frmCurrentPaths!Text2, sUserList)
If Not IsNull(vTempList) Then sUserList = vTempList
End If

WhosOn = sUserList

dbCurrent.Close
Set dbCurrent = Nothing

Exit_WhosOn:
Exit Function

Err_WhosOn:
Resume Exit_WhosOn

End Function

Private Function GetUserList(sSourcePath As String, sCurrentLogins) As
Variant
Dim iLDBFile As Integer, iStart As Integer
Dim iLOF As Integer, i As Integer
Dim sPath As String, x As String
Dim sLogStr As String, sLogins As String
Dim sMach As String, sUser As String
Dim rUser As UserRec ' Defined in General

On Error GoTo Err_GetUserList
GetUserList = Null
sPath = Left(sSourcePath, InStr(1, sSourcePath, ".")) + "LDB"

' Test for valid file, else Error

x = Dir(sPath)
iStart = 1
sLogins = sCurrentLogins
iLDBFile = FreeFile

' Iterate thru LDB file for login names.

Open sPath For Binary Access Read Shared As iLDBFile
iLOF = LOF(iLDBFile)
Do While Not EOF(iLDBFile)
Get iLDBFile, , rUser
With rUser
i = 1
sMach = ""
While .bMach(i) <> 0
sMach = sMach & Chr(.bMach(i))
i = i + 1
Wend
i = 1
sUser = ""
While .bUser(i) <> 0
sUser = sUser & Chr(.bUser(i))
i = i + 1
Wend
End With
sLogStr = sMach & " -- " & sUser
If sLogStr <> " -- " And InStr(sLogins, sLogStr) = 0 Then
sLogins = sLogins & sLogStr & ";"
End If
iStart = iStart + 64 'increment to next record offset
Loop
Close iLDBFile

Exit_GetUserList:
GetUserList = sLogins
Exit Function

Err_GetUserList:
If Err = 68 Then
MsgBox "Couldn't populate the list", 48, "No LDB File"
Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
Close iLDBFile
End If
Resume Exit_GetUserList

End Function
'*************************************************
 
Hi, Roger.
The WhosOn() code was originally created by Mark Nally for Access 2.0

Thanks for that information.
but
it is still perfectly valid (even though it is ancient).

It has one major shortcoming. It reads the LDB file, not the list of
current users actually logged on. Since no record is ever deleted from the
LDB file, it shows the list of users currently logged in, as well as all
users whose entry in the file has not yet been overwritten by a new user.
For example, if five concurrent users opened the database, then four of them
exited, then a new user opened the database, the LDB file would show the
first two users that are currently using the database, as well as three of
the previously users who have already exited the database. Not a very
accurate list.

On the other hand, the LDB Viewer shows all current users, and the KB
article I referenced in my post uses the user roster of all users currently
logged into the database.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


Roger Carlson said:
The WhosOn() code was originally created by Mark Nally for Access 2.0, but
it is still perfectly valid (even though it is ancient). The problem is you
are looking at the LDB file for the front end, rather than for the back end
database. To view the LDB file for the back end, you have to supply the
database name of a linked table.

The offending section of code is this:
Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sUserList = ""
vTempList = GetUserList(dbCurrent.Name, sUserList)

You need to send the file name (with the entire path) to the GetUserList
function.

One way to do this is with ADO:
'********************************
Function FindSource() As String
'this function finds the Connect string of the first
'linked table in the hidden 'MSysObjects' table. It then
'returns just the path & filename. Note: this assumes all
'of the linked tables are in the same file. If this is not
'true, you can replace the DFirst function with the name of
'a specific linked table.

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim strLinkedTable As String
cat.ActiveConnection = CurrentProject.Connection

Dim txtLinkedTable As String
txtLinkedTable = DFirst("Name", "MSysObjects", "[Type] = 6")
'MsgBox txtLinkedTable

Set tbl = cat.Tables(txtLinkedTable)
'MsgBox tbl.Properties("jet OLEDB:Link Datasource")
FindSource = tbl.Properties("jet OLEDB:Link Datasource")

End Function
'********************************

Then you can supply the back-end database file name like this:
vTempList = GetUserList(FindSource(), sUserList)


Note: for reference the WhosOn code is listed below:

'*************************************************
Option Compare Database
Option Explicit

'Originally written for Access 2 by Mark Nally
'Revised an updated for Access 97 by:

'

Private Type UserRec
bMach(1 To 32) As Byte ' 1st 32 bytes hold machine name
bUser(1 To 32) As Byte ' 2nd 32 bytes hold user name
End Type

Private Sub Form_Open(Cancel As Integer)

Me.LoggedOn.RowSource = WhosOn()

End Sub



Private Sub OKBtn_Click()

DoCmd.Close A_FORM, "frmLoggedOn"

End Sub

Private Sub UpdateBtn_Click()

Me.LoggedOn.RowSource = WhosOn()

End Sub


'-----------------------------------------------------------------
' Subject : WhosOn()
' Purpose : Will read *.LDB file and read who's currently
' logged on and their station name.
'
' The LDB file has a 64 byte record.
'
' The station name starts at byte 1 and is null
' terminated.
'
' Log-in names start at the 33rd byte and are
' also null terminated.
'
' I had to change the way the file was accessed
' because the Input() function did not return
' nulls, so there was no way to see where the
' names ended.
'---------------------------------------------------------------------------
----------
Private Function WhosOn() As String

On Error GoTo Err_WhosOn

Dim dbCurrent As DAO.Database
Dim sUserList As String, vTempList As Variant

' Get Path of current database
' and for an attached table path in a multi-user environment.

Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sUserList = ""
vTempList = GetUserList(dbCurrent.Name, sUserList)
If Not IsNull(vTempList) Then
sUserList = vTempList
vTempList = GetUserList(Forms!frmCurrentPaths!Text2, sUserList)
If Not IsNull(vTempList) Then sUserList = vTempList
End If

WhosOn = sUserList

dbCurrent.Close
Set dbCurrent = Nothing

Exit_WhosOn:
Exit Function

Err_WhosOn:
Resume Exit_WhosOn

End Function

Private Function GetUserList(sSourcePath As String, sCurrentLogins) As
Variant
Dim iLDBFile As Integer, iStart As Integer
Dim iLOF As Integer, i As Integer
Dim sPath As String, x As String
Dim sLogStr As String, sLogins As String
Dim sMach As String, sUser As String
Dim rUser As UserRec ' Defined in General

On Error GoTo Err_GetUserList
GetUserList = Null
sPath = Left(sSourcePath, InStr(1, sSourcePath, ".")) + "LDB"

' Test for valid file, else Error

x = Dir(sPath)
iStart = 1
sLogins = sCurrentLogins
iLDBFile = FreeFile

' Iterate thru LDB file for login names.

Open sPath For Binary Access Read Shared As iLDBFile
iLOF = LOF(iLDBFile)
Do While Not EOF(iLDBFile)
Get iLDBFile, , rUser
With rUser
i = 1
sMach = ""
While .bMach(i) <> 0
sMach = sMach & Chr(.bMach(i))
i = i + 1
Wend
i = 1
sUser = ""
While .bUser(i) <> 0
sUser = sUser & Chr(.bUser(i))
i = i + 1
Wend
End With
sLogStr = sMach & " -- " & sUser
If sLogStr <> " -- " And InStr(sLogins, sLogStr) = 0 Then
sLogins = sLogins & sLogStr & ";"
End If
iStart = iStart + 64 'increment to next record offset
Loop
Close iLDBFile

Exit_GetUserList:
GetUserList = sLogins
Exit Function

Err_GetUserList:
If Err = 68 Then
MsgBox "Couldn't populate the list", 48, "No LDB File"
Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
Close iLDBFile
End If
Resume Exit_GetUserList

End Function
'*************************************************
Sam said:
Hello

I have downloaded a form that shows who is logged on, however it only shows
one person as being logged on (me) when I know that several other people are
also logged on.. The code attached to the form is as below:--


Option Compare Database 'Use database order for string comparisons
Private Sub Form_Open(Cancel As Integer)
Me.LoggedOn.RowSource = WhosOn()
End Sub

Private Sub OKBtn_Click()
DoCmd.Close A_FORM, "LoggedOn"
End Sub

Private Sub UpdateBtn_Click()
Me.LoggedOn.RowSource = WhosOn()
End Sub

Is there a way to make this list everyone within the data base, or does
anyone have a good program/ form that does this ???
 
Hi, Sam.
If I am in the main menu, then the LDB viewer shows me as not being logged
in. If I choose the main data entry form, then it show me as being logged in.
Why is this happening???

The LDB Viewer has a limitation, too. It can only monitor one database file
at a time. If the LDB Viewer is monitoring the back end and your main menu
is not bound to a table linked to the back end, then you won't have the back
end database file open. If the main data entry form is bound to a linked
table, the LDB Viewer will show you as being logged into the back end.

If you need to monitor multiple database files, it would probably be best to
use the code in the KB article to display the "logged in" information. But
you can also use the LDB Viewer to bounce back and forth between two database
files. Just keep in mind that you can only view the information for one file
at a time.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


Sam said:
I have been using the LDB viewer but I seem to get a problem with it
recording who is on. I have set up menus on the data base (I am not using the
switchboard as it is too restrictive)

If I am in the main menu, then the LDB viewer shows me as not being logged
in. If I choose the main data entry form, then it show me as being logged in.
Why is this happening???

'69 Camaro said:
Hi, Roger.
The WhosOn() code was originally created by Mark Nally for Access 2.0

Thanks for that information.
but
it is still perfectly valid (even though it is ancient).

It has one major shortcoming. It reads the LDB file, not the list of
current users actually logged on. Since no record is ever deleted from the
LDB file, it shows the list of users currently logged in, as well as all
users whose entry in the file has not yet been overwritten by a new user.
For example, if five concurrent users opened the database, then four of them
exited, then a new user opened the database, the LDB file would show the
first two users that are currently using the database, as well as three of
the previously users who have already exited the database. Not a very
accurate list.

On the other hand, the LDB Viewer shows all current users, and the KB
article I referenced in my post uses the user roster of all users currently
logged into the database.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


Roger Carlson said:
The WhosOn() code was originally created by Mark Nally for Access 2.0, but
it is still perfectly valid (even though it is ancient). The problem is you
are looking at the LDB file for the front end, rather than for the back end
database. To view the LDB file for the back end, you have to supply the
database name of a linked table.

The offending section of code is this:
Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sUserList = ""
vTempList = GetUserList(dbCurrent.Name, sUserList)

You need to send the file name (with the entire path) to the GetUserList
function.

One way to do this is with ADO:
'********************************
Function FindSource() As String
'this function finds the Connect string of the first
'linked table in the hidden 'MSysObjects' table. It then
'returns just the path & filename. Note: this assumes all
'of the linked tables are in the same file. If this is not
'true, you can replace the DFirst function with the name of
'a specific linked table.

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim strLinkedTable As String
cat.ActiveConnection = CurrentProject.Connection

Dim txtLinkedTable As String
txtLinkedTable = DFirst("Name", "MSysObjects", "[Type] = 6")
'MsgBox txtLinkedTable

Set tbl = cat.Tables(txtLinkedTable)
'MsgBox tbl.Properties("jet OLEDB:Link Datasource")
FindSource = tbl.Properties("jet OLEDB:Link Datasource")

End Function
'********************************

Then you can supply the back-end database file name like this:
vTempList = GetUserList(FindSource(), sUserList)


Note: for reference the WhosOn code is listed below:

'*************************************************
Option Compare Database
Option Explicit

'Originally written for Access 2 by Mark Nally
'Revised an updated for Access 97 by:

'

Private Type UserRec
bMach(1 To 32) As Byte ' 1st 32 bytes hold machine name
bUser(1 To 32) As Byte ' 2nd 32 bytes hold user name
End Type

Private Sub Form_Open(Cancel As Integer)

Me.LoggedOn.RowSource = WhosOn()

End Sub



Private Sub OKBtn_Click()

DoCmd.Close A_FORM, "frmLoggedOn"

End Sub

Private Sub UpdateBtn_Click()

Me.LoggedOn.RowSource = WhosOn()

End Sub


'-----------------------------------------------------------------
' Subject : WhosOn()
' Purpose : Will read *.LDB file and read who's currently
' logged on and their station name.
'
' The LDB file has a 64 byte record.
'
' The station name starts at byte 1 and is null
' terminated.
'
' Log-in names start at the 33rd byte and are
' also null terminated.
'
' I had to change the way the file was accessed
' because the Input() function did not return
' nulls, so there was no way to see where the
' names ended.
'---------------------------------------------------------------------------
----------
Private Function WhosOn() As String

On Error GoTo Err_WhosOn

Dim dbCurrent As DAO.Database
Dim sUserList As String, vTempList As Variant

' Get Path of current database
' and for an attached table path in a multi-user environment.

Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sUserList = ""
vTempList = GetUserList(dbCurrent.Name, sUserList)
If Not IsNull(vTempList) Then
sUserList = vTempList
vTempList = GetUserList(Forms!frmCurrentPaths!Text2, sUserList)
If Not IsNull(vTempList) Then sUserList = vTempList
End If

WhosOn = sUserList

dbCurrent.Close
Set dbCurrent = Nothing

Exit_WhosOn:
Exit Function

Err_WhosOn:
Resume Exit_WhosOn

End Function

Private Function GetUserList(sSourcePath As String, sCurrentLogins) As
Variant
Dim iLDBFile As Integer, iStart As Integer
Dim iLOF As Integer, i As Integer
Dim sPath As String, x As String
Dim sLogStr As String, sLogins As String
Dim sMach As String, sUser As String
Dim rUser As UserRec ' Defined in General

On Error GoTo Err_GetUserList
GetUserList = Null
sPath = Left(sSourcePath, InStr(1, sSourcePath, ".")) + "LDB"

' Test for valid file, else Error

x = Dir(sPath)
iStart = 1
sLogins = sCurrentLogins
iLDBFile = FreeFile

' Iterate thru LDB file for login names.

Open sPath For Binary Access Read Shared As iLDBFile
iLOF = LOF(iLDBFile)
Do While Not EOF(iLDBFile)
Get iLDBFile, , rUser
With rUser
i = 1
sMach = ""
While .bMach(i) <> 0
sMach = sMach & Chr(.bMach(i))
i = i + 1
Wend
i = 1
sUser = ""
While .bUser(i) <> 0
sUser = sUser & Chr(.bUser(i))
i = i + 1
Wend
End With
sLogStr = sMach & " -- " & sUser
If sLogStr <> " -- " And InStr(sLogins, sLogStr) = 0 Then
sLogins = sLogins & sLogStr & ";"
End If
iStart = iStart + 64 'increment to next record offset
Loop
Close iLDBFile

Exit_GetUserList:
GetUserList = sLogins
Exit Function

Err_GetUserList:
If Err = 68 Then
MsgBox "Couldn't populate the list", 48, "No LDB File"
Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
Close iLDBFile
End If
Resume Exit_GetUserList

End Function
'*************************************************
Hello

I have downloaded a form that shows who is logged on, however it only
shows
one person as being logged on (me) when I know that several other people
are
also logged on.. The code attached to the form is as below:--


Option Compare Database 'Use database order for string comparisons
Private Sub Form_Open(Cancel As Integer)
Me.LoggedOn.RowSource = WhosOn()
End Sub

Private Sub OKBtn_Click()
DoCmd.Close A_FORM, "LoggedOn"
End Sub

Private Sub UpdateBtn_Click()
Me.LoggedOn.RowSource = WhosOn()
End Sub

Is there a way to make this list everyone within the data base, or does
anyone have a good program/ form that does this ???
 
Back
Top