VBA Code Unable To Create Text File on C:\ Drive In Acc2007

G

Gary

I have a VBA Code that works in Acc2000 and Acc2003 on XP Pro OS Sp3. I was
tesing the same code with Acc2007 with Win 7 Pro (64-bits). My Acc2003 has
Sp3 and my Acc2007 has Sp2.

This is the VBA Code that I used:

Dim FullPath As String
Dim QueryName As String
Dim filename As Variant

filename = Forms![Video Export]![Text22]
FullPath = "c:\" & Trim(filename) & ".txt"
AvidQueryName = "OutputToVideo"
DoCmd.TransferText acExportDelim, "Comma Delimited Spec 2007", _
QueryName, FullPath, False


I noticed the following:
1) Running with Acc2003 with Win 7 Pro (64-bits), it works. Text
file was
created in the c:\ drive.

2) Running with Acc2007 with Win 7 Pro (64-bits), it gives me the
following
error: "Run-time error '3051' The Microsoft Office Access
data base
engine cannot open or write to the file. It is already opened
exclusively
by another user, or you need permission to view and write its
data."

When I changed the "FullPath" to write the text file in side
an existing
folder - it works ! This was the change:

FullPath = "c:\Test\" & Trim(filename) & ".txt"

The Win 7 Pro (64-bits) is the same for both of the about test.

It seems that Acc 2007 is not allowing me to write or create a text file in
the c:\ drive.

Can someone help me here ?? What would I need to allow this to happen ???

Thank You,

G
 
S

Stefan Hoffmann

hi Gary,

It seems that Acc 2007 is not allowing me to write or create a text file in
the c:\ drive.

Can someone help me here ?? What would I need to allow this to happen ???
An ordinary user has not the NTFS permissions to do that since Windows
2000. Use one of your known folders instead of this:

http://msdn.microsoft.com/en-us/library/bb776911(VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb762584(VS.85).aspx

E.g. the desktop or the documents folder.


mfG
--> stefan <--
 
A

AccessVandal via AccessMonster.com

You have a variable "AvidQueryName" declared somewhere(?) and you have a
variable "QueryName". Which is the correct variable in the DoCmd for
"QueryName"?

It is also possible that you may having an existing file (same path and file
name) and may have prevented you from editing the file or replacing the file.
This is the VBA Code that I used:
Dim FullPath As String
Dim QueryName As String
Dim filename As Variant

filename = Forms![Video Export]![Text22]
FullPath = "c:\" & Trim(filename) & ".txt"
AvidQueryName = "OutputToVideo"
DoCmd.TransferText acExportDelim, "Comma Delimited Spec 2007", _
QueryName, FullPath, False
snip.......
 
G

Gary

AccessVandal via AccessMonster.com said:
You have a variable "AvidQueryName" declared somewhere(?) and you have a
variable "QueryName". Which is the correct variable in the DoCmd for
"QueryName"?

It is also possible that you may having an existing file (same path and file
name) and may have prevented you from editing the file or replacing the file.
This is the VBA Code that I used:
Dim FullPath As String
Dim QueryName As String
Dim filename As Variant

filename = Forms![Video Export]![Text22]
FullPath = "c:\" & Trim(filename) & ".txt"
AvidQueryName = "OutputToVideo"
DoCmd.TransferText acExportDelim, "Comma Delimited Spec 2007", _
QueryName, FullPath, False
snip.......

--
Please Rate the posting if helps you.




.
 
G

Gary

No duplicates. I checked that for sure !!

Gary



AccessVandal via AccessMonster.com said:
You have a variable "AvidQueryName" declared somewhere(?) and you have a
variable "QueryName". Which is the correct variable in the DoCmd for
"QueryName"?

It is also possible that you may having an existing file (same path and file
name) and may have prevented you from editing the file or replacing the file.
This is the VBA Code that I used:
Dim FullPath As String
Dim QueryName As String
Dim filename As Variant

filename = Forms![Video Export]![Text22]
FullPath = "c:\" & Trim(filename) & ".txt"
AvidQueryName = "OutputToVideo"
DoCmd.TransferText acExportDelim, "Comma Delimited Spec 2007", _
QueryName, FullPath, False
snip.......

--
Please Rate the posting if helps you.




.
 
A

AccessVandal via AccessMonster.com

Forgot to add.

filename = Forms![Video Export]![Text22]
FullPath = "c:\" & Trim(filename) & ".txt"

"Comma Delimited Spec 2007"

The DoCmd will always name the file as "Comma Delimited Spec 2007". But your
variable is not in the DoCmd as it is surposed to be "filename". So are you
certain?
 
S

Stefan Hoffmann

hi Gary,

You used the word "ordinary user", how about one with "admin" rights ???
This dependes on the Windows version and the installation type. At least
as Admin you can give you the permissions to do so.

mfG
--> stefan <--
 
G

Gary

Yes. Remember that the same program works on Win 7 Pro (64-bits) with
Acc2003. I tried that.

I then ran it in a virtual machine with the same Win 7 Pro (64-bits) with
Acc 2007 and I get this issue. If I change the Fullpath to an existing
folder and not dirrectly to the c:\ drive, it works !

Do you think I lack permission in the virtual machine ?? How do I check
the permission in Win 7 ??


Thank You,

Gary

AccessVandal via AccessMonster.com said:
Forgot to add.

filename = Forms![Video Export]![Text22]
FullPath = "c:\" & Trim(filename) & ".txt"

"Comma Delimited Spec 2007"

The DoCmd will always name the file as "Comma Delimited Spec 2007". But your
variable is not in the DoCmd as it is surposed to be "filename". So are you
certain?
No duplicates. I checked that for sure !!

Gary

--
Please Rate the posting if helps you.




.
 
A

AccessVandal via AccessMonster.com

I'm not using Win7, so I'm not sure about the newer security setup. Seems
like a lack of permissions to me. Since you're using VM with Win7, it might
be the reason. Have you check your VM forums yet?

Do you know that Access 2007 need Trusted Location? Did you include the file
path for that Trusted Location? It's worth a try to see if that's the case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top