msgbox not working

G

Guest

I got the following code somewhere, Cant remember where but I would like the
code to send a message to the employees that are logged on, to log out(that
is what the message contains) loggedon is the listbox that contains the list
of people loggedon.....

Private Sub Command1_Click()
Dim strUser As String
Dim i As Integer
Dim strMessage2Send As String
Dim strMessage As String
Dim RunBatch As Double

strMessage = Me.Message

For i = 0 To LoggedOn.ListCount - 1
If LoggedOn.Selected(i) = True Then
strUser = LoggedOn.Column(0, i)
MsgBox Left(strUser, InStr(strUser, "--") - 1)
strMessage2Send = strMessage2Send & "net send " & strUser & " """ & _
strMessage & """" & Chr(13) & Chr(13)
End If
Next
If strMessage2Send = "" Then
MsgBox "Please enter a computer name/user ID"

Exit Sub
End If
RunBatch = Shell(strMessage2Send, vbHide)
MsgBox "Message Sent"
End Sub
 
B

BruceM

For one thing, I think that Left(strUser, InStr(strUser, "--") - 1) needs to
be a string. For another, you have defined strMessage2Send as itself plus
something else. I don't see how that will work, but even if it does in some
way I can't picture, it will never be "" since it contains a text string.
Also, you need to End If before you Exit Sub.
Couldn't say about the RunBatch part.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top