dbTalk Databases Forums  

VBA CreateFile

comp.databases.ms-access comp.databases.ms-access


Discuss VBA CreateFile in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bsn
 
Posts: n/a

Default VBA CreateFile - 08-17-2011 , 04:47 AM






Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne

Reply With Quote
  #2  
Old   
Phil
 
Posts: n/a

Default Re: VBA CreateFile - 08-17-2011 , 05:38 AM






On 17/08/2011 10:47:51, "bsn" wrote:
Quote:
Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne


Hi Bjarne, only guessing, but I suspect the "&" is not the correct
concatenation symbol for DOS

see
http://www.dostips.com/DtTipsStringM...oncat enation

Phil

Reply With Quote
  #3  
Old   
bsn
 
Posts: n/a

Default Re: VBA CreateFile - 08-17-2011 , 06:00 AM



"Phil" skrev i meddelelsen news:j2g5n2$r8h$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 10:47:51, "bsn" wrote:
Quote:
Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne


Hi Bjarne, only guessing, but I suspect the "&" is not the correct
concatenation symbol for DOS

see
http://www.dostips.com/DtTipsStringM...oncat enation
------------------------------------------------------
Hi Phil
thx for answer...
I make the line in VBA code(not DOS) - creating a file with
FileSystemObject...out in a resulting .bat file...
The task is to get VBA syntax correct...i think...
Bjarne

Reply With Quote
  #4  
Old   
Phil
 
Posts: n/a

Default Re: VBA CreateFile - 08-17-2011 , 08:50 AM



On 17/08/2011 12:00:25, "bsn" wrote:
Quote:
"Phil" skrev i meddelelsen news:j2g5n2$r8h$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 10:47:51, "bsn" wrote:
Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne



Hi Bjarne, only guessing, but I suspect the "&" is not the correct
concatenation symbol for DOS

see
http://www.dostips.com/DtTipsStringM...oncat enation
------------------------------------------------------ Hi Phil
thx for answer...
I make the line in VBA code(not DOS) - creating a file with
FileSystemObject...out in a resulting .bat file...
The task is to get VBA syntax correct...i think...
Bjarne


Sorry, maybe I was wrong, I appreciate you are using VBA, but I think the
bat file is a DOS file

Phil

Reply With Quote
  #5  
Old   
bsn
 
Posts: n/a

Default Re: VBA CreateFile - 08-17-2011 , 10:54 AM



"Phil" skrev i meddelelsen news:j2ggvc$m9f$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 12:00:25, "bsn" wrote:
Quote:
"Phil" skrev i meddelelsen news:j2g5n2$r8h$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 10:47:51, "bsn" wrote:
Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne



Hi Bjarne, only guessing, but I suspect the "&" is not the correct
concatenation symbol for DOS

see
http://www.dostips.com/DtTipsStringM...oncat enation
------------------------------------------------------ Hi Phil
thx for answer...
I make the line in VBA code(not DOS) - creating a file with
FileSystemObject...out in a resulting .bat file...
The task is to get VBA syntax correct...i think...
Bjarne

Sorry, maybe I was wrong, I appreciate you are using VBA, but I think the
bat file is a DOS file.
-----------------------------------------------------------
yes - the resulting .bat file is a dos file...
Here is my VBA code...if it helps...

Code:
Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(myPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close
/Code

Bjarne

Reply With Quote
  #6  
Old   
Phil
 
Posts: n/a

Default Re: VBA CreateFile - 08-17-2011 , 11:42 AM



On 17/08/2011 16:54:20, "bsn" wrote:
Quote:

"Phil" skrev i meddelelsen news:j2ggvc$m9f$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 12:00:25, "bsn" wrote:
"Phil" skrev i meddelelsen news:j2g5n2$r8h$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 10:47:51, "bsn" wrote:
Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne



Hi Bjarne, only guessing, but I suspect the "&" is not the correct
concatenation symbol for DOS

see
http://www.dostips.com/DtTipsStringM...oncat enation
------------------------------------------------------ Hi Phil
thx for answer...
I make the line in VBA code(not DOS) - creating a file with
FileSystemObject...out in a resulting .bat file...
The task is to get VBA syntax correct...i think...
Bjarne


Sorry, maybe I was wrong, I appreciate you are using VBA, but I think the
bat file is a DOS file.
-----------------------------------------------------------
yes - the resulting .bat file is a dos file...
Here is my VBA code...if it helps...

Code:
Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(myPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close
/Code

Bjarne


I have put in the complete module

Function Test(Mappe As String, MyPath As String)
'Print Test("C:\testFolder\Filename.txt", "C:\Phil Data\Access\MDB
2010\TestFile") Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
'Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
'MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(MyPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close

End Function
Not sure exactly what your input is

The second line is what you type in the immediate window

The output of TestFile is:
echo off
copy C:\testFolder\Fil C:\testFolder\Filtest_

Not, I suspect, what you want, but all on one line.
Windows 7, Access 2010, and the Testfile viewed using Notepad
Phil

Reply With Quote
  #7  
Old   
bsn
 
Posts: n/a

Default Re: VBA CreateFile - 08-18-2011 , 02:48 PM



"Phil" skrev i meddelelsen news:j2gr15$fd5$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 16:54:20, "bsn" wrote:
Quote:

"Phil" skrev i meddelelsen news:j2ggvc$m9f$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 12:00:25, "bsn" wrote:
"Phil" skrev i meddelelsen news:j2g5n2$r8h$1 (AT) speranza (DOT) aioe.org...

On 17/08/2011 10:47:51, "bsn" wrote:
Hi NG...
I try to make a file with CreateFile
It works fine - but...

When i make this line :

MyFile.WriteLine ("copy " & Folder & Filename & " " & Folder & "test_" &
Filename)...

The resulting file looks like this(3 lines) :

copy
C:\testFolder\Filename.txt
D:\testFolder\Filename.txt

I want the result on 1 line ...
copy C:\testFolder\Filename.txt D:\testFolder\test_Filename.txt

Help wanted...

Bjarne



Hi Bjarne, only guessing, but I suspect the "&" is not the correct
concatenation symbol for DOS

see
http://www.dostips.com/DtTipsStringM...oncat enation
------------------------------------------------------ Hi Phil
thx for answer...
I make the line in VBA code(not DOS) - creating a file with
FileSystemObject...out in a resulting .bat file...
The task is to get VBA syntax correct...i think...
Bjarne


Sorry, maybe I was wrong, I appreciate you are using VBA, but I think the
bat file is a DOS file.
-----------------------------------------------------------
yes - the resulting .bat file is a dos file...
Here is my VBA code...if it helps...

Code:
Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(myPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close
/Code

Bjarne


I have put in the complete module

Function Test(Mappe As String, MyPath As String)
'Print Test("C:\testFolder\Filename.txt", "C:\Phil Data\Access\MDB
2010\TestFile") Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
'Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
'MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(MyPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close

End Function
Not sure exactly what your input is

The second line is what you type in the immediate window

The output of TestFile is:
echo off
copy C:\testFolder\Fil C:\testFolder\Filtest_

Not, I suspect, what you want, but all on one line.
Windows 7, Access 2010, and the Testfile viewed using Notepad
Phil
---------------------------------------------------------------------------------
I am using the exact same configuration...
When i use ur function as is, Linie2 comes out in one line, but when i go
back to
my path(variables) the output comes in 3 lines again...
Its just like when the path is getting longer, the output comes in 3 lines
like the starting point of this thread...

I discovered that the Left and Mid function dont give the right answer...
ex :
Drive = Left(Path,3) should give the Drive(C:\), but it only gives 1
letter(C)...
Are A2010 very buggy or what...??? its annoying...
Bjarne

Reply With Quote
  #8  
Old   
Phil
 
Posts: n/a

Default Re: VBA CreateFile - 08-18-2011 , 04:47 PM



Quote:
I have put in the complete module

Function Test(Mappe As String, MyPath As String)
'Print Test("C:\testFolder\Filename.txt", "C:\Phil Data\Access\MDB
2010\TestFile") Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
'Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
'MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(MyPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close

End Function
Not sure exactly what your input is

The second line is what you type in the immediate window

The output of TestFile is:
echo off
copy C:\testFolder\Fil C:\testFolder\Filtest_

Not, I suspect, what you want, but all on one line.
Windows 7, Access 2010, and the Testfile viewed using Notepad
Phil
---------------------------------------------------------------------------------
I am using the exact same configuration... When i use ur function as is,
Linie2 comes out in one line, but when i go back to
my path(variables) the output comes in 3 lines again...
Its just like when the path is getting longer, the output comes in 3 lines
like the starting point of this thread...

I discovered that the Left and Mid function dont give the right answer...
ex :
Drive = Left(Path,3) should give the Drive(C:\), but it only gives 1
letter(C)...
Are A2010 very buggy or what...??? its annoying...
Bjarne


Hi Bjarne
No problems with Access 2010 32 bit, that is what I use. Machine is Windows 7
64 bit. I did apply SP1 to Office 2010 a few weeks ago, and that proved a
disaster. All sorts of things that were working then crashed.
Removed SP1 and all is now back to normal.

What precisely are you using as the input for Mappe and MyPath, so that I can
test them on my computer.

Phil

Reply With Quote
  #9  
Old   
bsn
 
Posts: n/a

Default Re: VBA CreateFile - 08-19-2011 , 01:56 AM



"Phil" skrev i meddelelsen news:j2k19c$rso$1 (AT) speranza (DOT) aioe.org...


Quote:
I have put in the complete module

Function Test(Mappe As String, MyPath As String)
'Print Test("C:\testFolder\Filename.txt", "C:\Phil Data\Access\MDB
2010\TestFile") Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\")
Drev = Mid(Mappe, 1, 3)
Sti = Mid(Mappe, 4, x)
'Fil = Filnavn
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
'MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(MyPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close

End Function
Not sure exactly what your input is

The second line is what you type in the immediate window

The output of TestFile is:
echo off
copy C:\testFolder\Fil C:\testFolder\Filtest_

Not, I suspect, what you want, but all on one line.
Windows 7, Access 2010, and the Testfile viewed using Notepad
Phil
---------------------------------------------------------------------------------
I am using the exact same configuration... When i use ur function as is,
Linie2 comes out in one line, but when i go back to
my path(variables) the output comes in 3 lines again...
Its just like when the path is getting longer, the output comes in 3 lines
like the starting point of this thread...

I discovered that the Left and Mid function dont give the right answer...
ex :
Drive = Left(Path,3) should give the Drive(C:\), but it only gives 1
letter(C)...
Are A2010 very buggy or what...??? its annoying...
Bjarne


Hi Bjarne
No problems with Access 2010 32 bit, that is what I use. Machine is Windows
7
64 bit. I did apply SP1 to Office 2010 a few weeks ago, and that proved a
disaster. All sorts of things that were working then crashed.
Removed SP1 and all is now back to normal.

What precisely are you using as the input for Mappe and MyPath, so that I
can
test them on my computer.
-----------------------------------------------------------------------------------------------------------
I use Win7 32 bit + Access 2010

x = InStrRev(Filer, "\")
Mappe = Mid(Filer, 1, x) '---> Public Variable
MyPath = CurrentProject.Path & "\bsn.bat"

Output Linie2 =
copy
D:\Users\Bjarne\Desktop\vinduespudser_2010_Win7.ac cde
D:\Users\Bjarne\Desktop\bsndata_vinduespudser_2010 _Win7.accde

Output should be in 1 line...

Bjarne

thx for ur patience...
Bjarne

Reply With Quote
  #10  
Old   
Phil
 
Posts: n/a

Default Re: VBA CreateFile - 08-19-2011 , 03:17 AM



On 19/08/2011 07:56:29, "bsn" wrote:
Quote:

"Phil" skrev i meddelelsen news:j2k19c$rso$1 (AT) speranza (DOT) aioe.org...




Hi Bjarne,

Other than you are using Windows 32 bit & I am using Windows 64 bit, no
difference.

Try


Function Test(Mappe As String, MyPath As String)
'Print Test("D:\Users\Bjarne\Desktop\vinduespudser_2010_W in7.accde",
CurrentProject.Path & "\bsn.bat") Dim fso, myFile
Dim Linie1, Linie2 As String
Dim Drev, Sti, Fil As String
Dim x As Single
x = InStrRev(Mappe, "\") ' Last \
Drev = Mid(Mappe, 1, 3) ' Drive
Sti = Mid(Mappe, 4, x - 3) ' ***** Path *** Alter this
Fil = Right(Mappe, Len(Mappe) - x) ' **** File **** Alter this
Linie1 = "echo off"
Linie2 = "copy " & Drev & Sti & Fil & " " & Drev & Sti & "test_" & Fil
'MsgBox Linie1 & vbCrLf & Linie2
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(MyPath, True)
myFile.WriteLine (Linie1)
myFile.WriteLine (Linie2)
myFile.Close

End Function

Output is
echo off
copy D:\Users\Bjarne\Desktop\vinduespudser_2010_Win7.ac cde
D:\Users\Bjarne\Desktop\test_vinduespudser_2010_Wi n7.accde

Phil

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.