I need to do a "net send" command to active database users for a
message.
Is this possible with Access 2002?
say, user9000 is login, I can send all active login database users a
message sayin "the database will close in 1min".
thanks again.
Perry
I don't know if the UserRoster displays the Windows user id (it displays
the machine name) or the login ID into the app. I suppose you could
create a table and use the function at
http://www.mvps.org/access/api/api0008.htm to stuff the user name and
login time to the app.
Ron Paii wrote to you on July 30th about NetSend.
I modified a function that reads the LDB file and returns a list of
computers with that MDB open. I also added a Shell call to send a message to
each computer.
'---------------------------------------
' Open a .ldb file and get list of users
' Sends a message to each user
' returns a list format for an "IN" clause of a query
'
Public Function UserListMsg(DBName As String, strMessage as String) As
String
On Error GoTo UserListMsgErr
Dim UserName As String, UserRight As String, UserList As String
Dim ldbName As String
Dim iNumUsers As Integer
ldbName = Left(DBName, Len(DBName) - 4)
ldbName = Trim(ldbName & ".ldb")
iNumUsers = 0
Open ldbName For Input Shared As #1
Do While Not EOF(1)
UserName = Input(31, #1)
' Send the message to computer
Shell("NET SEND " & UserName & " """ & strMessage & """")
iNumUsers = iNumUsers + 1
UserRight = Input(5, #1)
UserList = UserList & "'" & Trim$(UserName) & "',"
Loop
Close #1
UserListMsg = UserList
Exit Function
UserListMsgErr:
UserListMsg = ""
If Err = 53 Then '.ldb file not found
ElseIf Err = 62 Then
Close #1
Exit Function
Else
MsgBox Err.Number & " - " & Err.Description & ", Function: NumUsers"
End If
End Function
Sorry
Shell("NET SEND " & UserName & " """ & strMessage & """")
Should be
Shell("NET SEND " & Trim$(UserName) & " """ & strMessage & """")
P.S.: I am green in programming, in order for me to enable a button to
carry out the codes, I changed your code to a private sub, does that
matter?
Perry
Add these function to the module
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenW" (ByVal
lpstring As Long) As Long
Private Function TrimNull(startstr As String) As String
TrimNull = Left$(startstr, lstrlen(StrPtr(startstr)))
End Function
Perry
?UserListMsg("R:SYSTEM1.LDB","Test")
Step though the code and tell me which line failed.
Perry
Perry
> Never mind about my last question, but a
> more simplier one, how do I call a public
> function to run with a button?
If you are not going to do anything with the returned value, you can just
put the function name preceded by an = sign in the Click event property of
the Button Control. Or you can create a code snippet that calls the
function.
Larry Linson
Microsoft Access MVP