Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process DOS batch file from command button 1

Status
Not open for further replies.

data1025

IS-IT--Management
Apr 14, 2004
29
US
Is there a way to process a DOS command (a batch file) from an Access form? I would like to create a command button to process a batch file, but need 2 variables from the form included, so when I run batch.bat %1 %2, the variables are carried from access to DOS and the command runs.
 
Surely the Shell command will do that for you.


Something like

Code:
Private Sub cmdButton_Click()
Dim dblRetValue As Double
dblRetValue = Shell("\\server\path\folder\Batch.bat " & param1 & ", " & param2, vbHide)

End Sub



'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
In your example, would Param1 and Param2 be my field names?

My fields are Printer1 and Computer1, and I would like those values to be in %1 and %2, respectively.

 
Yes, The Shell command is just like issuing a Command Line instruction into the DOS window so if you have the name of Printer1 in a variable then swap the variable name for Param1 etc.

If you have a text box control on the form that is bound to the field containing the data then you can use thetext box control name.

If you mean you want the literal text string "Printer1" then use

dblRetValue = Shell("\\server\path\folder\Batch.bat Printer1, Computer1", vbHide)

(Replace vbHide with any of the other consts if you want to see what is going on. )

If you just have the data in fields then you'll need to get them you of the field so that the code can be aware of the value.
The easiest way would be binding them to controls on the form if that is possible.





'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
I don't want the literal text Printer1, just the field "Printer1" and its value will flow to DOS.

I would like to make a form, with 2 drop down boxes. Each drop down will represent one of the variables. One drop down will have printers, and one will have computers. When I select both, and click the command button, I would like the values of what I selected in the boxes to output to DOS in the variables. I hope this makes sense.

Since I am not saving a record to the database when this happens, how would I call the values? Do I need to use the "me.printer1" or something?
 
dim strPrinter as string
dim strComp as string

strPrinter = Combo1.value
strComputer = Combo2.value

Dim dblRetValue As Double
dblRetValue = Shell("\\server\path\folder\Batch.bat " & strPrinter & ", " & strComputer, vbHide)
 
I have this working, somewhat. I need one more value. The value I need is in the table that I am pulling the Printer1 from. How can I obtain this?

Table CitrixPrinters
Field = Printer1
Field = PCName

My combo box lists all Printer1 values for the table. Once I select the value, I need the PCName from it too. Possible?
 
Well, I thought I had it. The line where the shell command is, is giving me a Compile error / syntax error. What am I doing wrong? All the fields I want are there, as I can see their values in the msgbox that pops up when I click the button.


Private Sub PrinterID2_AfterUpdate()
Me.PID = DLookup("MachineName", "CitrixPrinters", "PrinterID1 = '" & Me.PrinterID2 & "'")

End Sub

Private Sub RunBatch_Click()
On Error GoTo Err_RunBatch_Click

Dim strPrinterID As String
Dim strComp As String
Dim strCompSource As String
Dim msgtxt As String

strPrinterID = PrinterID2
strComp = User2
strCompSource = PID
msgtxt = "Printer " & strPrinterID & " on " & strCompSource & " has been added to computer " & User2
Dim dblRetValue As Double
MsgBox msgtxt
dblRetValue = Shell("\\dohsfphpe1601\netdata\sysadmin\inventorylists\ipdatabase_printerassign.bat " & strComp & ", " & strCompSource & ", " & StrPrinterID2, vbHide)




Exit_RunBatch_Click:
Exit Sub

Err_RunBatch_Click:
MsgBox Err.Description
Resume Exit_RunBatch_Click

End Sub

 
Changed the StrPrinterID2 to StrPrinterID (my typing error) in the DblRetValue line. Still same error tho.
 
I am getting a Compile/Syntax error on the line that starts with DblRetValue =

Can someone view my above code and tell me what may be wrong? There is no other error than the above.
 
dblRetValue = Shell("\\dohsfphpe1601\netdata\sysadmin\inventorylists\ipdatabase_printerassign.bat " & strComp & ", " & strCompSource & ", " & StrPrinterID2, vbHide)

Would you care to explaine the "2" that I've highlighted in the above code ?



Also:-

Is PrinterId1 a combo box ?
and if so is it's RowSource CitrixPrinters ?

If so then using
Private Sub PrinterID2_AfterUpdate()
Me.PID = DLookup("MachineName", "CitrixPrinters", "PrinterID1 = '" & Me.PrinterID2 & "'")
End Sub

is real bad practice and a very slow way of doing things.


Better to include MachineName in the columns that PrinterID2 knows about
Ie
RowSource = "SELECT PrinterId1, MachineName FROM CitrixPrinters"

Then the PrinterID2_After_Update event is totally unnecessary
and you delete the
Dim strCompSource As String
and the
strCompSource = PID
in the main code and use
Code:
dblRetValue = Shell("\\dohsfphpe1601\netdata\sysadmin\inventorylists\ipdatabase_printerassign.bat " & strComp & ", " & PrinterID1.Column(1) & ", " & PrinterID2, vbHide)
instead.

(I'm guessing that the Str in the front of StrPrinterID2 is the error that is causing your syntax error.)





'ope-that-'elps.


G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top