Run batch file through a Access GUI

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

Guest

I am creating a GUI thru Access. This GUI is not connected to a database.
There is a batch file I like to initiate thru this GUI. For example there
will be a batch file to install a network printer for a user. The user will
press a number or press a printername from a listbox to initiate this batch
file. Is this possible in Access VBA? If it is how should I go about doing
this? I am clueless. I appreciate any help.
The following component is in the GUI:

Building name: Optionboxes
Department name: Listbox
Printer name: Listbox
The user will choose a building name, which has many departments.When the
user choose a department, a list of printers belong to that specific
department will show up in the Printer name listbox. Then the user will
hilite the correct printer name, press either OK or Enter. This will
initiate installing the printer thru the batch file.

Please let me know if this is possible.
Thanks a lot.
 
Hi Thadi

This is straight forward:

Create the batch file using the FileSystemObject object then launch it using
the Shell command. e.g.

Set fs = CreateObject("Scripting.FileSystemObject")
Set batchfile = fs.CreateTextFile("c:\yourfile.bat", True)
With batchfile
.WriteLine ("line 1 of the batch file goes here")
.WriteLine ("line 2 of the batch file goes here")
.... etc. ...
.Close
End With

RetVal = Shell("c:\yourfile.bat")



Build up each line by pulling in the values of the listboxes, e.g.

..WriteLine ("Printer Name: " & Me.ListBox1)
etc.

Cheers.

BW
 
Thanks for the great suggestion. I at least have something to start with
now. I am not creating a batchfile. Batchfile is residing in a different
path. I will point the code toward that path and it will automatically
pickup that path and start installing the printer. So I will not need the
FileSystemObject. Does that make sense?
Thanks.
 
Hi

Sorry but I don't quite understand what you are looking to achieve.

Is there just 1 batch file, or 1 for each printer. What does the batch file
contain? I presume it contains the Command Lines to install the printers such
as the Prnmngr.vbs command perhaps?

Please explain and I'll try and help.

Cheers.

BW
 
Yes there is one batch file for each printer. Each batch file(eiter .bat or
..vbs) installs each printer. Thanks a lot.
 
Hi

Yes it does make sense (I think!).

So, in your list box you need the names and paths to the batch files.

Set the list box's properties as follows:

'Row Source Type' to 'Value List'
'Column Count' to '2'
'Column Widths' to '0' (that's a zero which will make the first
column invisible)
'Row Source' to "path to printer 1 batch file";"Name of printer
1 to display"; etc.
i.e. build up a list of printers with the full path and batch file name
followed by the name of that printer you want displayed in the list box. Each
value needs to enclosed in " 's and seperated by a ; . e.g.

"N:\path to batch file\Printer1.bat";"Sales Department";"N:\path to batch
file\Printer2.bat";"Despatch Department"; ....

Then all you have to do is run the Shell command picking up the value of the
list box in a Command Button or the TextBoxes onclick/double click event. e.g.

RetVal = Shell(Me.ListBox)

Note that if the path is always the same you could shorten the entries by
just putting the batch file name in the listbox and building the rest in the
Shell command. e.g.

The listbox's RowSource becomes:

"Printer1.bat";"Sales Department";"Printer2.bat";"Despatch Department"; ....

and the Shell command,

RetVal = Shell("N:\path to batch files\" & Me.ListBox)

Good luck.

BW
 
Back
Top