Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 30th, 2004, 03:05 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating, Writing to and Deleting Text Files

Hi all,

I am trying to achieve the following functionality using VBA code:

Create a text file
Store a string in that text file, the string itself being contained in a String variable.
(Then I actually run a batch file using the Shell command which will call that particular string from the text file just created and execute certain functionality)
Delete the created text file

(This whole creation and deletion of text file is actually taking place within a Do Until loop. This is being done as I cannot figure out any direct way to pass parameters to a batch file at the same time that I am executing it, using the Shell command. Thus the text file acts as a workaround to that problem.)

Can anyone please also shed some light on how to read a string stored in a text file from a batch file. I am just hoping that this step itself is not too complicated.

Chow
Goels


Reply With Quote
  #2 (permalink)  
Old October 1st, 2004, 04:13 AM
Authorized User
 
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this routine to read a text file into a string in VBA:

Function Read_TextFile_to_String(strReadFileName) As String

    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Dim FS, rf, textStream

    'eg. strReadFile = "c:\data\projects\lintec\RO08289.txt"

    Set FS = CreateObject("Scripting.FileSystemObject")
    Set rf = FS.GetFile(strReadFileName)
    Set textStream = rf.OpenAsTextStream(ForReading, TristateUseDefault)

    ' Method 1. read all file at once
    Read_TextFile_to_String = textStream.ReadAll
    '
    textStream.Close

End Function


Cheers Ray
Reply With Quote
  #3 (permalink)  
Old October 1st, 2004, 04:16 AM
Authorized User
 
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I was too quick on the button, the example line should read:

    'eg. strReadFileName = "c:\data\projects\lintec\RO08289.txt"



Cheers Ray
Reply With Quote
  #4 (permalink)  
Old October 1st, 2004, 06:06 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Ray,

Thanks a lot for your prompt reply. To update you on the problem, i was actually trying to run an Axys (the financial software which runs at my place ) script file from VBA code and pass parameters to it at the same time. Since there seemed to be no way of running these script files directly from VBA i was working on this workaround wherein batch files are used. This is so because a batch file has a direct command to run an Axys script. I had also mailed the support people for Axys yesterday regarding this and today they showed me how an Axys script file can be run from VBA code. It is something like:

Shell "\\lvamfs01\advent\Axys\Axys32.Exe script testappend3.scr -exit"

Here first comes the full-path name of the execuatble file for the software, then the Script command, then the name of the script file and then -exit which is an Axys command to end Axys after the script file has been executed. I gave this command here as i hope the format could be of some use when trying to execute script files which use different software. But the problem of passing parameters to this script file is still unresolved, for i tried giving parameters as :

Shell "\\lvamfs01\advent\Axys\Axys32.Exe script testappend3.scr batchpassvalue -exit"

where the batchpassvalue variable has the value "mts" stored in it but what happens is that when the code is executed instead of the value stored in batchpassvalue getting passed , it itself gets passed as the value. Now Ray i tried combinations with batchpassvalue like

%batchpassvalue%
&batchpassvalue&

but the whole thing gets passed as the value itself.

Is there a way Ray through which we can pass the value stored in batchpassvalue instead of it itself getting passed ?

I have contacted the people at Axys again and am waiting their reply. I shall let you know of the answer as soon as i get it. Else if there is no such way i will have to take the long route of batch files.

Get back to you soon and Thanking You once again for your help.

Chow
Goels

Reply With Quote
  #5 (permalink)  
Old October 1st, 2004, 02:38 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Ray,

One can acheive the desired functionality thru:

Shell ("\\lvamfs01\advent\Axys\Axys32.Exe script testappend3.scr " & batchpassvalue & " -exit")

Cheers
Goels

Reply With Quote
  #6 (permalink)  
Old February 27th, 2006, 05:25 AM
Registered User
 
Join Date: Feb 2006
Location: London, , United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, i am exactly in the same situation as you were in, i was hoping to run a program in dos prompt by changing its current directory from vba, i used shell to open the cmd.exe, then i could not pass any parameters, like say i wanted to enter the name of the file to be run in the dos prompt or to change the current directory to c:, from your post i came to know that its not possible to pass the parameters directly, but the code you used,
Shell ("C:\WINNT\system32\CMD.exe script testappend3.scr 'param here?' -exit")

so, did you manage to get around the problem, if so, could you pass me the code, thank you.


Quote:
quote:Originally posted by goels
 Hi all,

I am trying to achieve the following functionality using VBA code:

Create a text file
Store a string in that text file, the string itself being contained in a String variable.
(Then I actually run a batch file using the Shell command which will call that particular string from the text file just created and execute certain functionality)
Delete the created text file

(This whole creation and deletion of text file is actually taking place within a Do Until loop. This is being done as I cannot figure out any direct way to pass parameters to a batch file at the same time that I am executing it, using the Shell command. Thus the text file acts as a workaround to that problem.)

Can anyone please also shed some light on how to read a string stored in a text file from a batch file. I am just hoping that this step itself is not too complicated.

Chow
Goels


Reply With Quote
  #7 (permalink)  
Old January 29th, 2007, 04:38 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

We use Advent Axys in our company. I use the following VBA line from Excel to call the scr script:
Code:
Private Sub cmdExportfromAxys_Click()
Shell ("g:\axys3\axys32.exe script export.scr")
End Sub
But I'm getting the following pop up error in Axys:
'File cenviw.exe not found'

Any suggestion or advice much appreicated. Also the script runs fins in Axys itself


Quote:
quote:Originally posted by goels
 Dear Ray,

One can acheive the desired functionality thru:

Shell ("\\lvamfs01\advent\Axys\Axys32.Exe script testappend3.scr " & batchpassvalue & " -exit")

Cheers
Goels

Reply With Quote
  #8 (permalink)  
Old January 30th, 2007, 11:51 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

We use Advent Axys in our company. I use the following VBA line from Excel to call the scr script:

Private Sub cmdExportfromAxys_Click()
Shell ("g:\axys3\axys32.exe script export.scr")
End Sub


But I'm getting the following pop up error in Axys:
'File cenviw.exe not found'

Any suggestion or advice much appreicated. Also the script runs fins in Axys itself


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading, Writing and deleting access record, Help! vadarv Access VBA 1 August 28th, 2006 06:36 AM
Deleting files using a listbox control Indo77 ASP.NET 1.0 and 1.1 Basics 1 April 20th, 2006 10:43 AM
deleting files as session expires jaisonkmathews General .NET 4 October 18th, 2004 12:07 AM
Reading/Creating/Writing Excel FIles p_nut33 C# 1 September 2nd, 2003 12:17 PM
Deleting directories and files ... DennisTh VB.NET 2002/2003 Basics 5 June 12th, 2003 02:30 PM



All times are GMT -4. The time now is 06:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.