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
  #21  
Old   
bsn
 
Posts: n/a

Default Re: VBA CreateFile - 08-22-2011 , 04:50 PM






"bsn" <bsnSNABELAoncableDOTdk> skrev i en meddelelse
news:4e5173d8$0$56784$edfadb0f (AT) dtext02 (DOT) news.tele.dk...
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2r8ic$oea$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 23:34:56, "bsn" wrote:

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2ojhi$6v6$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 15:51:24, "bsn" wrote:
VinduespudserProgramD:\Users\Bjarne\Desktop\vindue spudser_2010_Win7.accde

Have you tries Debug.Print
Dir("D:\Users\Bjarne\Desktop\vinduespudser_2010_Wi n7.accde") Does the
file
exist? Phil

Yes - VinduespudserProgram variable holds the path+dbname...
Bjarne



Sorry then Bjarne. I give up.

The VBA I gave you works for me OK.
Might be worth having a look at the .Bat file with a hex editor, to see
what
characters are giving you the unwanted line feeds. This is a free editor
http://www.hhdsoftware.com/free-hex-editor Phil

Thx for ur patience...
Ill try the hexeditor, and Ill try another setup to - winxp+access2003....
I tell u about the result later...
Bjarne
HexEditor result :
65 63 68 6f 20 6f 66 66 0d 0a 22 63 6f 70 79 20
0d 0a 44 3a 5c 55 73 65 72 73 5c 42 6a 61 72 6e
65 5c 44 65 73 6b 74 6f 70 5c 76 69 6e 64 75 65
73 70 75 64 73 65 72 5f 32 30 31 30 5f 57 69 6e
37 2e 61 63 63 64 65 20 0d 0a 44 3a 5c 55 73 65
72 73 5c 42 6a 61 72 6e 65 5c 44 65 73 6b 74 6f
70 5c 62 73 6e 64 61 74 61 5f 76 69 6e 64 75 65
73 70 75 64 73 65 72 5f 32 30 31 30 5f 57 69 6e
37 2e 61 63 63 64 65 22 0d 0a
echo off..
"copy ..
D:\Users\Bjarne\Desktop\vinduespudser_2010_Win7.ac cde ..
D:\Users\Bjarne\Desktop\bsndata_vinduespudser_2010 _Win7.accde"
/HexEditor result

Can u read it...???

The winxp+access2003 gave the same result as above...:-((

Bjarne

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

Default Re: VBA CreateFile - 08-22-2011 , 04:58 PM






"Access Developer" <accdevel (AT) gmail (DOT) com> skrev i en meddelelse
news:9bebgqF96fU1 (AT) mid (DOT) individual.net...
Quote:
I don't use the File System Object, though various "experts" have
recommended it. (But they don't mention that some {perhaps many} system
adminstrators delete the Windows Scripting Host from all systems under
their control because they consider it a security list. Some even go so
far as to periodically check to see if some "rogue software" has reinstated
it.) That does not seem to be your problem.

And, back when the "experts" began recommending it as "latest and
greatest", I compared various functionality using FSO versus identical
functionality using the built-in VBA File I/O statements, and, in no case
was the FSO version either shorter or discernably faster.

Your problem appears from the discussion to be in concatenating the
strings.

I suggest you perform the concatenation separately, and test that it
executed correctly by using Debug.Print and examining the output in the
Immediate Window.
"concatenation separately", am I not doing it now...???

Quote:
But, IMNSHO, the best advice you received was to use the built-in VBA File
I/O statement "FileCopy" to copy the external files from within Access.
I tried the FileCopy statement - the result was a file error...
Runtime Error 52
Bad file name or number

Quote:
As a matter of fact, I've recently started a series of presentations and
examples to refresh our memory about these i/o statements in VBA. They are
almost identical to the statements from QuickBASIC, TurboBASIC, and other
early versions of BASIC, long before there was either Windows or VBA.
thx for answer
Bjarne

Quote:
"bsn" <bsnSNABELAoncableDOTdk> wrote in message
news:4e5173d8$0$56784$edfadb0f (AT) dtext02 (DOT) news.tele.dk...

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2r8ic$oea$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 23:34:56, "bsn" wrote:

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2ojhi$6v6$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 15:51:24, "bsn" wrote:
VinduespudserProgramD:\Users\Bjarne\Desktop\vindue spudser_2010_Win7.accde

Have you tries Debug.Print
Dir("D:\Users\Bjarne\Desktop\vinduespudser_2010_Wi n7.accde") Does the
file
exist? Phil

Yes - VinduespudserProgram variable holds the path+dbname...
Bjarne



Sorry then Bjarne. I give up.

The VBA I gave you works for me OK.
Might be worth having a look at the .Bat file with a hex editor, to see
what
characters are giving you the unwanted line feeds. This is a free editor
http://www.hhdsoftware.com/free-hex-editor Phil

Thx for ur patience...
Ill try the hexeditor, and Ill try another setup to -
winxp+access2003....
I tell u about the result later...
Bjarne



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

Default Re: VBA CreateFile - 08-23-2011 , 02:55 AM



On 22/08/2011 22:50:18, "bsn" wrote:
Quote:
"bsn" <bsnSNABELAoncableDOTdk> skrev i en meddelelse
news:4e5173d8$0$56784$edfadb0f (AT) dtext02 (DOT) news.tele.dk...

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2r8ic$oea$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 23:34:56, "bsn" wrote:

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2ojhi$6v6$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 15:51:24, "bsn" wrote:
VinduespudserProgramD:\Users\Bjarne\Desktop\vindue spudser_2010_Win7.accde

Have you tries Debug.Print
Dir("D:\Users\Bjarne\Desktop\vinduespudser_2010_Wi n7.accde") Does the
file
exist? Phil

Yes - VinduespudserProgram variable holds the path+dbname...
Bjarne



Sorry then Bjarne. I give up.

The VBA I gave you works for me OK.
Might be worth having a look at the .Bat file with a hex editor, to see
what
characters are giving you the unwanted line feeds. This is a free editor
http://www.hhdsoftware.com/free-hex-editor Phil

Thx for ur patience...
Ill try the hexeditor, and Ill try another setup to - winxp+access2003....
I tell u about the result later...
Bjarne

HexEditor result :
65 63 68 6f 20 6f 66 66 0d 0a 22 63 6f 70 79 20
0d 0a 44 3a 5c 55 73 65 72 73 5c 42 6a 61 72 6e
65 5c 44 65 73 6b 74 6f 70 5c 76 69 6e 64 75 65
73 70 75 64 73 65 72 5f 32 30 31 30 5f 57 69 6e
37 2e 61 63 63 64 65 20 0d 0a 44 3a 5c 55 73 65
72 73 5c 42 6a 61 72 6e 65 5c 44 65 73 6b 74 6f
70 5c 62 73 6e 64 61 74 61 5f 76 69 6e 64 75 65
73 70 75 64 73 65 72 5f 32 30 31 30 5f 57 69 6e
37 2e 61 63 63 64 65 22 0d 0a
echo off..
"copy ..
D:\Users\Bjarne\Desktop\vinduespudser_2010_Win7.ac cde ..
D:\Users\Bjarne\Desktop\bsndata_vinduespudser_2010 _Win7.accde"
/HexEditor result

Can u read it...???

The winxp+access2003 gave the same result as above...:-((

Bjarne


No problem reading it. the significant bit is the 0d 0a combination which in VBA terms is Chr$(13) & Chr$(10) or VbCrLf
That sequence appears after echo off
after Win7.accde ........ Note the space after the accde
after the final Win7.accde"
So at least we have eliminated some problem in the way the file is displayed.
The line feeds are definately thers.

Phil

Reply With Quote
  #24  
Old   
Access Developer
 
Posts: n/a

Default Re: VBA CreateFile - 08-23-2011 , 03:40 PM



"bsn" <bsnSNABELAoncableDOTdk> wrote

Quote:
Your problem appears from the discussion to be in concatenating the
strings.

I suggest you perform the concatenation separately, and test that it
executed correctly by using Debug.Print and examining the output in the
Immediate Window.

"concatenation separately", am I not doing it now...???
From your first post in this thread:

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

No, you are concatenating in the same statement in which you write the line.

Try:

Dim strFirst as String

strFirst = "copy" & Folder
debug.print strFirst
strFirst = strFirst & Filename
debug.print strFirst
strFirst = strFirst & " "
debug.print strFirst
strFirst = strFirst & Folder
debug.print strFirst
strFirst = strFirst & "test_"
debug.print strFirst
strFirst = strFirst & Filename

I used separate concatenations for each term, so it would be easier to
determine which term might be causing a problem.

Quote:
But, IMNSHO, the best advice you received was to use the built-in VBA
File
I/O statement "FileCopy" to copy the external files from within Access.

I tried the FileCopy statement - the result was a file error...
Runtime Error 52
Bad file name or number
I've never had trouble with FileCopy provided I used a valid file name,
either fully-qualified with path, or just the file name if in the current
folder. Try using debug.print to display the file names in the Immediate
Window. I am currently using Win XP and Access 2003 (with all the current
service packs and fixes that Microsoft distributes for both).

Was, perhaps, the file open when you tried "FileCopy"? The Help for
FileCopy in Access 2003 ends with the Remark: "If you try to use the
FileCopy statement on a currently open file, an error occurs."

Just to refresh my memory, I just tried the following and both FileCopy
commands were successful:

FileCopy "C:\\data\Access\Access2003\CopyThisFileOne.tx t",
"C:\\data\Access\Access2003\CopiedFileOne.txt"
FileCopy "CopyThisFileTwo.txt", "CopiedFileTwo.txt"

The commands, as tested, were in the click event of a Command Button.

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access

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

Default Re: VBA CreateFile - 08-24-2011 , 02:22 AM



"Access Developer" <accdevel (AT) gmail (DOT) com> skrev i en meddelelse
news:9bihghFnkbU1 (AT) mid (DOT) individual.net...
Quote:
"bsn" <bsnSNABELAoncableDOTdk> wrote

Your problem appears from the discussion to be in concatenating the
strings.

I suggest you perform the concatenation separately, and test that it
executed correctly by using Debug.Print and examining the output in the
Immediate Window.

"concatenation separately", am I not doing it now...???

From your first post in this thread:

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

No, you are concatenating in the same statement in which you write the
line.

Try:

Dim strFirst as String

strFirst = "copy" & Folder
debug.print strFirst
strFirst = strFirst & Filename
debug.print strFirst
strFirst = strFirst & " "
debug.print strFirst
strFirst = strFirst & Folder
debug.print strFirst
strFirst = strFirst & "test_"
debug.print strFirst
strFirst = strFirst & Filename

I used separate concatenations for each term, so it would be easier to
determine which term might be causing a problem.

But, IMNSHO, the best advice you received was to use the built-in VBA
File
I/O statement "FileCopy" to copy the external files from within
Access.

I tried the FileCopy statement - the result was a file error...
Runtime Error 52
Bad file name or number

I've never had trouble with FileCopy provided I used a valid file name,
either fully-qualified with path, or just the file name if in the current
folder. Try using debug.print to display the file names in the Immediate
Window. I am currently using Win XP and Access 2003 (with all the current
service packs and fixes that Microsoft distributes for both).

Was, perhaps, the file open when you tried "FileCopy"? The Help for
FileCopy in Access 2003 ends with the Remark: "If you try to use the
FileCopy statement on a currently open file, an error occurs."

Just to refresh my memory, I just tried the following and both FileCopy
commands were successful:

FileCopy "C:\\data\Access\Access2003\CopyThisFileOne.tx t",
"C:\\data\Access\Access2003\CopiedFileOne.txt"
FileCopy "CopyThisFileTwo.txt", "CopiedFileTwo.txt"

The commands, as tested, were in the click event of a Command Button.
thx very much for answer...
I found the error at last...:-))
I had a vbCrLf inserted in my code in a function...:-((
I got the hint from the hex editor...
Bjarne

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

Default Re: VBA CreateFile - 08-24-2011 , 02:23 AM



"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2r8ic$oea$1 (AT) speranza (DOT) aioe.org...
Quote:
On 20/08/2011 23:34:56, "bsn" wrote:

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:j2ojhi$6v6$1 (AT) speranza (DOT) aioe.org...
On 20/08/2011 15:51:24, "bsn" wrote:
VinduespudserProgramD:\Users\Bjarne\Desktop\vindue spudser_2010_Win7.accde

Have you tries Debug.Print
Dir("D:\Users\Bjarne\Desktop\vinduespudser_2010_Wi n7.accde") Does the
file
exist? Phil

Yes - VinduespudserProgram variable holds the path+dbname...
Bjarne



Sorry then Bjarne. I give up.
thx very much for answers...
I found the error at last...:-))
I had a vbCrLf inserted in my code in a function...:-((
I got the hint from the hex editor...
Bjarne

Reply With Quote
  #27  
Old   
Access Developer
 
Posts: n/a

Default Re: VBA CreateFile - 08-24-2011 , 11:24 AM



I've generally found that there is some other way to implement functionality
than creating executable code in code, just because it is so prone to
hard-to-debug problems such as this. My recommendation to use FileCopy
still stands. Just because you managed to get past this particular
stumbling block isn't going to make your approach less complex or less prone
to error in the future. Good luck with your application.

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access


"bsn" <bsnSNABELAoncableDOTdk> wrote

Quote:
"Access Developer" <accdevel (AT) gmail (DOT) com> skrev i en meddelelse
news:9bihghFnkbU1 (AT) mid (DOT) individual.net...
"bsn" <bsnSNABELAoncableDOTdk> wrote

Your problem appears from the discussion to be in concatenating the
strings.

I suggest you perform the concatenation separately, and test that it
executed correctly by using Debug.Print and examining the output in the
Immediate Window.

"concatenation separately", am I not doing it now...???

From your first post in this thread:

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

No, you are concatenating in the same statement in which you write the
line.

Try:

Dim strFirst as String

strFirst = "copy" & Folder
debug.print strFirst
strFirst = strFirst & Filename
debug.print strFirst
strFirst = strFirst & " "
debug.print strFirst
strFirst = strFirst & Folder
debug.print strFirst
strFirst = strFirst & "test_"
debug.print strFirst
strFirst = strFirst & Filename

I used separate concatenations for each term, so it would be easier to
determine which term might be causing a problem.

But, IMNSHO, the best advice you received was to use the built-in VBA
File
I/O statement "FileCopy" to copy the external files from within
Access.

I tried the FileCopy statement - the result was a file error...
Runtime Error 52
Bad file name or number

I've never had trouble with FileCopy provided I used a valid file name,
either fully-qualified with path, or just the file name if in the current
folder. Try using debug.print to display the file names in the Immediate
Window. I am currently using Win XP and Access 2003 (with all the
current service packs and fixes that Microsoft distributes for both).

Was, perhaps, the file open when you tried "FileCopy"? The Help for
FileCopy in Access 2003 ends with the Remark: "If you try to use the
FileCopy statement on a currently open file, an error occurs."

Just to refresh my memory, I just tried the following and both FileCopy
commands were successful:

FileCopy "C:\\data\Access\Access2003\CopyThisFileOne.tx t",
"C:\\data\Access\Access2003\CopiedFileOne.txt"
FileCopy "CopyThisFileTwo.txt", "CopiedFileTwo.txt"

The commands, as tested, were in the click event of a Command Button.

thx very much for answer...
I found the error at last...:-))
I had a vbCrLf inserted in my code in a function...:-((
I got the hint from the hex editor...
Bjarne

Reply With Quote
  #28  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: VBA CreateFile - 08-24-2011 , 04:22 PM



"Access Developer" <accdevel (AT) gmail (DOT) com> wrote in
news:9bebgqF96fU1 (AT) mid (DOT) individual.net:

Quote:
And, back when the "experts" began recommending it as "latest and
greatest", I compared various functionality using FSO versus
identical functionality using the built-in VBA File I/O
statements, and, in no case was the FSO version either shorter or
discernably faster.
I haven't tested, but it may be more aware of Windows Vista/Win7 UAC
issues. I have noticed that some code I run using Dir() and other
standard VBA file-related functions fails on Vista/Win7 machines,
and I'm hoping the FSO is more security-aware.

Also, the FSO provides better network-based performance for
determining if a resource exists.

And I have yet to encounter a system where it was disabled, even
though I was one of the people who was most suspicious of the WSH
(because of its early exploitation by virus writers).

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #29  
Old   
Tony Toews
 
Posts: n/a

Default Re: VBA CreateFile - 08-24-2011 , 10:14 PM



On Wed, 24 Aug 2011 09:23:31 +0200, "bsn" <bsnSNABELAoncableDOTdk>
wrote:

Quote:
I found the error at last...:-))
I had a vbCrLf inserted in my code in a function...:-((
I got the hint from the hex editor...
Glad you found the problem. Just for grins I did a bit of testing.

Create a string variable with vbcrlf in the middle. If you put a stop
in the code and highlight the variable name the hover tooltip does not
show the vbCrLf. However if you debug.print the variable the value
shows up as two lines.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/

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.