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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing and external file. 1

Status
Not open for further replies.

jtlawn

Programmer
Mar 23, 2000
15
0
0
US
I am a new user to ACCESS, I am using ACCESS 2000. I want to be able to execute and external file from a button on a form. Our Company was using Approach and just recently swithced, in Approach I had to create a package in an object, I can do this in ACCESS also, but I need two buttons one execute the object and one to import the data. Can't I code something in VBA that will execute an external file and then import the results to a table. HELP!!!! <p> <br><a href=mailto:jtlawn@hotmail.com>jtlawn@hotmail.com</a><br><a href= > </a><br>
 
What kind of external file are you trying to execute?<br>
<br>
this is an example of how to open a say Word, and then a certain file in Word. <br>
<br>
Dim WordPath, DocPath As String<br>
Dim Retval As Variant<br>
WordPath = &quot;C:\Program Files\Microsoft Office\Office\WinWord.exe&quot;<br>
DocPath = &quot;c:\My Documents\file1.doc&quot;<br>
Retval = Shell(WordPath & &quot; &quot; & DocPath, vbMinimizedFocus)<br>
<br>
if you give more specifics i may be able to help customize this statement for you.<br>
<br>
And then you can put a statement such as this in the same VBA (so you only need one button) to import the data.<br>
<br>
<br>
Dim Tablpath As String<br>
Dim DocPath2 As String<br>
Dim FileDef As String<br>
<br>
Tablpath = &quot;the table to get the data&quot;<br>
DocPath2 = &quot;the file that was just created&quot;<br>
FileDef = &quot;the specs for the file&quot;<br>
'you have to create and save these through the import wizard<br>
DoCmd.TransferText acImportFixed, FileDef, TablPath, DocPath2, 0<br>
<br>
all of this is dependant on what kind of executable you want to do, and what you want to import, but your theory is very possible.<br>
<br>
<p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
I am trying to execute a procedure out of a software product called 'application systems' or 'AS'. We are using their command client piece to extract data from our mainframe to a PC. I am using AS, because it gives me the connectivity to the mainframe and allows me to write my code directly into it. That piece works and I drop the file on my PC into a CSV file, which I then can import into ACCESS. What I would like to be able to do is, put a button on a form or switchboad, that will download the file and import the file into ACCESS. We are using IBM personal communication 4.2 & 4.3 as our communication software. <p> <br><a href=mailto:jtlawn@hotmail.com>jtlawn@hotmail.com</a><br><a href= > </a><br>
 
alright, so CSV is a database file?<br>
what you would need to do is use the <br>
<br>
DoCmd.TransferDatabase<br>
<br>
command, and then define the database type as CSV, and then the path and file names, and the table to import it into.<br>
CSV may not be a regularly recognized database type on your Access version, and would require a quick reinstall in order to be able to import that type of file (you jsut have to specify this part during the installment process).<br>
<br>
the procedure is relatively simple, you just create the button and put the DoCmd in the Click procedure for teh button. <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
Okay, I think I can do the import, but I am still not sure of the download part:<br>
<br>
Are you saying: DoCmd.TransferDatabase=C:\DAS\WORK\PGM1.as<br>
<br>
Where PGM1.as is the name of the job that will actually run the job that will download the file for me.<br>
<br>
Thanks <p> <br><a href=mailto:jtlawn@hotmail.com>jtlawn@hotmail.com</a><br><a href= > </a><br>
 
If you want to run a program from Access then look at the Shell statement<br>
x = Shell(&quot;C:\DAS\WORK\PGM1.as&quot;,1)<br>
DoCmd.TransferText acImportFixed, &quot;Specname&quot;, &quot;YourTable&quot;, .CSV_Name, True<br>
<br>
And to Import it as &quot;famousb&quot; said use Docmd.Tranfer...<br>
Type in Docmd. and you will see a list of items it can do press TR and you will see transfer Press the Space bar to grab it.<br>
Then double click on Tranfer.. and press the F1 key to bring up help. Then you can investigate all of it parameters to see how to use it.<br>
<br>
I would Import it manually then create a &quot;Specification&quot; and Save it to use in your docmd. <br>
<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
actually, the code would look like this for your example:<br>
<br>
<b>Dim JobPath As String<br>
Dim Retval As Variant<br>
JobPath = &quot;C:\DAS\WORK\PGM1.as&quot;<br>
Retval = Shell(JobPath)<br>
<br>
DoCmd.TransferDatabase acImport, &quot;CSV&quot;, &quot;C:\DAS\WORK\????&quot;, acTable, &quot;Source Table Name&quot;,&quot;Destination Table Name&quot;, 0<br>
</b><br>
&quot;CSV&quot; describes the type of database you care to import (that's what you described earlier, and i said you may have to reinstall access for)<br>
&quot;C:\DAS\WORK\????&quot; is your database path and name that was created by PGM1.as<br>
acTable is saying that you want to import a table<br>
Then enter the &quot;source table name&quot; (from your database)<br>
Then enter the &quot;destination table name&quot; (in your Access db)<br>
<br>
<br>
<p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
I have been able to run the executable, but now my problem is with trying to import the CSV file.&nbsp;&nbsp;Would I be better off having my executable create an ODBC file instead?<br><br>If so how would that code look and how do I actually make set the ODBC connection.&nbsp;&nbsp;I have tried, but I am not sure what exactly I should be doing?<br><br>WE have always been a mainframe shop, so this whole process is new. The executable in the first step is calling a program that will execute on the host and create a file on my PC, that is why I am wondering what file type would be best for me to create.<br><br>Thank You.&nbsp;&nbsp; <p> <br><a href=mailto:jtlawn@hotmail.com>jtlawn@hotmail.com</a><br><a href= > </a><br>
 
ok, refresh and update me as to your situation. you get the executable to work and it creates the CSV file automatically, and this works just fine, correct?<br>now you are having trouble importing the CSV into Access using the TransferDatabase procedure, look in a Macro, and check to see if CSV is a type of database that Access recognizes for your installation.<br><br>if not, you can either re-install as per above, or you could create a .txt file (if your other program can do that) and import that inot Access.&nbsp;&nbsp;there are actually many options for you. <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
I was able to get the code to finally work.&nbsp;&nbsp;I was using transferDatabase and I needed to use transferText.&nbsp;&nbsp;I also needed to use use a command line string to first execute the software, then execute the specific job.&nbsp;&nbsp;Here is a sample of the code.&nbsp;&nbsp;Thank You for all your help:<br><br>Dim Policy As String<br>Dim JobPath As String<br>Dim Retval As Variant<br>JobPath = &quot;D:\das\daszcomm.exe D:\das\work\agtphone.as /q&quot;<br>Retval = Shell(JobPath)<br>DoCmd.DeleteObject acTable, &quot;Agtphone&quot;<br>DoCmd.TransferText acImportDelim, &quot;&quot;, &quot;agtphone&quot;, &quot;D:\das\work\agtphone.txt&quot;, True, &quot;&quot; <p> <br><a href=mailto:jtlawn@hotmail.com>jtlawn@hotmail.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top