Sending multiple commands to the CMD

S

SJW_OST

I hope I can describe this how I am intending.
I know how to open a Command prompt (cmd.exe) using Access2003. What I am
trying to figure out is how can I send a command like "Net Send" using a
table of ID's and then enter a message to goto the ID's selected?
As I am sure you know, when I am using cmd.exe (command prompt) I type
something like the following to send someone a message.

C:\> Net Send IM12345 Please change jobs.

When I pull up cmd.exe using Access2003, how can I get Access to enter the
"Net Send" command, pull the ID(s) from a table and allow the sender to enter
a message to be sent to the selected ID(s).
Is this even possible?
Please help. Thank you in advance!
 
P

pietlinden

I hope I can describe this how I am intending.
I know how to open a Command prompt (cmd.exe) using Access2003. What I am
trying to figure out is how can I send a command like "Net Send" using a
table of ID's and then enter a message to goto the ID's selected?
As I am sure you know, when I am using cmd.exe (command prompt) I type
something like the following to send someone a message.

C:\> Net Send IM12345 Please change jobs.

When I pull up cmd.exe using Access2003, how can I get Access to enter the
"Net Send" command, pull the ID(s) from a table and allow the sender to enter
a message to be sent to the selected ID(s).
Is this even possible?
Please help. Thank you in advance!

here's the code for NET SEND
http://www.vbnet.mvps.org/code/network/netmessagebuffersend.htm
 
S

SJW_OST

I have followed the instructions to the letter but each time I try to switch
from design view to form view I get;

Run-time error '2185':
You can't reference a property or method for a control unless the control
has the focus.

When I debug it goes to "Text1.Text = TrimNull(tmp)" in the follwoing
portion of the code provided on the site. What have I done wrong?

Private Sub Form_Load()

Dim tmp As String

'pre-load the text boxes with
'the local computer name for testing
tmp = Space$(MAX_COMPUTERNAME + 1)
Call GetComputerName(tmp, Len(tmp))

Text1.Text = TrimNull(tmp)
Text2.Text = TrimNull(tmp)
Text3.Text = TrimNull(tmp)

End Sub
 
D

Douglas J. Steele

You haven't done anything wrong. The issue is that the original code was
written for Visual Basic programmers, and there are some significant
differences between controls available for forms in VB and in Access. You
got bit by one of these differences. In VB, you use the Text property to get
the value from a control. In Access, you use the Value property: you can
only use the Text property when the control has focus.

Since the default property for a text box is its Value property, you should
be able to get away with

Me!Text1 = TrimNull(tmp)
Me!Text2 = TrimNull(tmp)
Me!Text3 = TrimNull(tmp)

If not, use

Me!Text1.Value = TrimNull(tmp)
Me!Text2.Value = TrimNull(tmp)
Me!Text3.Value = TrimNull(tmp)
 
S

SJW_OST

Ok, so that worked, after some tweeking, and I can send a message to 1 ID at
a time. However, I need to be able to get the code to send to multiple IDs if
I choose, which I will be. I have built a table that has a column for the ID,
Manager & Unit. I need to be able to choose any one of these.

ID, of course, would be 1 message at a time to that person.
Manager would send to all IDs assisgned to the manager selected.
Unit would send to all IDs assigned to the unit selected.

I'll need to make a dropdown window so I can choose which I want to use but
how to tie in the code. Also,I think I would need to put some sort of loop in
the code to perform the action and if I am looking at it correctly, it would
be somewhere in the following code, but I can't figure out where or how. Help?

Private Function NetSendMessage(msgData As NetMessageData) As String

Dim success As Long

'assure that the OS is NT ..
'NetMessageBufferSend can not
'be called on Win9x
If IsWinNT() Then

With msgData

'if To name omitted return error and exit
If .sSendTo = "" Then

NetSendMessage = GetNetSendMessageStatus(ERROR_INVALID_PARAMETER)
Exit Function

Else

'if there is a message
If Len(.sMessage) Then

'convert the strings to unicode
.sSendTo = StrConv(.sSendTo, vbUnicode)
.sMessage = StrConv(.sMessage, vbUnicode)

'Note that the API could be called passing
'vbNullString as the SendFrom and sServerName
'strings. This would generate the message on
'the sending machine.
If Len(.sServerName) > 0 Then
.sServerName = StrConv(.sServerName, vbUnicode)
Else
.sServerName = vbNullString
End If

If Len(.sSendFrom) > 0 Then
.sSendFrom = StrConv(.sSendFrom, vbUnicode)
Else
.sSendFrom = vbNullString
End If

'change the cursor and show. Control won't return
'until the call has completed.
'Screen.MousePointer = vbHourglass

success = NetMessageBufferSend(.sServerName, _
.sSendTo, _
.sSendFrom, _
.sMessage, _
ByVal Len(.sMessage))

Screen.MousePointer = vbNormal

NetSendMessage = GetNetSendMessageStatus(success)

End If 'If Len(.sMessage)
End If 'If .sSendTo
End With 'With msgData
End If 'If IsWinNT

End Function
 
P

pietlinden

Ok, so that worked, after some tweeking, and I can send a message to 1 ID at
a time. However, I need to be able to get the code to send to multiple IDsif
I choose, which I will be. I have built a table that has a column for the ID,
Manager & Unit. I need to be able to choose any one of these.

ID, of course, would be 1 message at a time to that person.
Manager would send to all IDs assisgned to the manager selected.
Unit would send to all IDs assigned to the unit selected.

I'll need to make a dropdown window so I can choose which I want to use but
how to tie in the code. Also,I think I would need to put some sort of loopin
the code to perform the action and if I am looking at it correctly, it would
be somewhere in the following code, but I can't figure out where or how. Help?

IF you're going to manually choose which machines will receive the
message, and the group always changes, I would use an unbound listbox
and just iterate through the itemsSelected collection. (There are
several examples on Access web, just look up "listbox" www.mvps.org/access)

if you're gonna get the information from a table or query, you can do
something like this:
Private Sub cmdSendMessages_Click()

Dim MsgData As NetMessageData
Dim sSuccess As String
CONST strMSG as String = "SOME MESSAGE"
dim rs as DAO.recordset
set rs=DbEngine(0)(0).OpenQuerydef("qrySendToRecipients")

With MsgData
.sServerName = Text1.Text
.sSendTo = rs.Fields("RecipientComputer")
.sSendFrom = "NetworkNameOfSendingComputer"
.sMessage = "Some Message"
End With

sSuccess = NetSendMessage(MsgData)

Label1.Caption = sSuccess

End Sub
 
S

SJW_OST

This is great, but I have one question. Where in the code from the web site
do I insert this? Please know I am rather new with Access code. Thank you for
your help.
 

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