?
Solved

Automate Batch with Access 2013

Posted on 2013-11-25
6
Medium Priority
?
1,908 Views
Last Modified: 2013-11-26
Hello,

I created a simple database in Access 2013. I setup a query on certain fields if one of the Yes/No fields is true. Then, I created a Saved Export to export the True results to a CSV file. The CSV file contains values I need to run a command line utility. The command line utility uses the data from the CSV file to know what to do. Now, I want to automate this.

How do I create a macro to run the Saved Export and then run the MS-DOS batch file? Can this be done easily? If I need to create something else instead of a Macro then what is it? I would like to be able to create the CSV file and run the batch file from within Access 2013 so that I don't have to bounce between the desktop and Access.

Thanks in advance.
0
Comment
Question by:jhieb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 39676542
You can write a macro, but better, write a VBA function. I recommend you create a form and placed a button on it. Double click on the button in the Form Designer and a VB editor will appear.

There you need to write a simple code:
Private Sub cmdButton1_Click()
On Error GoTo Err_cmdButton1_Click

    Dim strFileName, stAppName As String

    stAppName = CurrentProject.Path & "\yourbatchfile.bat"
    
    strFileName = CurrentProject.Path & "\Export.csv"

    DoCmd.TransferText acExportDelim, "qryResults", strFileName, False

    Call Shell(stAppName, 1)

Exit_cmdButton1_Click:
    Exit Sub

Err_cmdButton1_Click:
    Msg = "Error # " & str(Err.Number) & Chr(13) & Err.Description
    MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
    Resume Exit_cmdButton1_Click

End Sub

Open in new window

Please replace in the code above the "qryResults" with the real query name.
Also fix the batch file name, and the name of the Export.csv.
Please note that the code assumes that the batch file and the csv file are in the same folder as your database file
0
 
LVL 1

Author Comment

by:jhieb
ID: 39679633
Thank you. I may have missed something. My query does not make the export. Instead, I created a "Saved Export" that creates the CSV file. I don't know how to do that with a query so that is why I made an export and saved the steps.
0
 
LVL 25

Expert Comment

by:chaau
ID: 39679638
The code I have provided does not use the report. It uses the query directly
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jhieb
ID: 39679653
I placed the database, and batch file in the same directory.

OK. I am making progress. I modified your script and changed the names of the batch file, csv file, and query name. When I click on the button I get the following error:

Error #3625
The text file specification 'qryExport' does not exist. You cannot import, export, or link using the specification.

Here is the modified version:

Private Sub Command0_Click()
On Error GoTo Err_cmdButton1_Click

    Dim strFileName, stAppName As String

    stAppName = CurrentProject.Path & "\MyBatch.cmd"
   
    strFileName = CurrentProject.Path & "\Batchlist.txt"

    DoCmd.TransferText acExportDelim, "qryExport", strFileName, False

    Call Shell(stAppName, 1)

Exit_cmdButton1_Click:
    Exit Sub

Err_cmdButton1_Click:
    Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description
    MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
    Resume Exit_cmdButton1_Click

End Sub
0
 
LVL 25

Assisted Solution

by:chaau
chaau earned 2000 total points
ID: 39679671
Please add a comma here. I have made a typo the first time.
DoCmd.TransferText acExportDelim, , "qryExport", strFileName, False
0
 
LVL 1

Author Closing Comment

by:jhieb
ID: 39679681
This works very well. Thank you very much for the help!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question