[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Automate Batch with Access 2013

Posted on 2013-11-25
6
Medium Priority
?
1,939 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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