Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS Access Create external File

Posted on 2011-03-23
14
Medium Priority
?
248 Views
Last Modified: 2012-05-11
I have the below code.  I am trying to create a file and write to it and its not working.  Any ideas?
Dim fns As String
fns = "c:\List.txt"

Dim fso As FileSystemObject
Dim a As Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile(fns, True)
a.WriteLine ("This is a test.")
a.Close

  Open fns For Output As #3
  Write #3, "TEST"
  Close #3

Open in new window

0
Comment
Question by:CipherIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 75
ID: 35204222
Although I have been known to read minds, this is not one of those times.  Can you define "It's not working in detail" ?

mx
0
 
LVL 75
ID: 35204231
And actually, it seems to work for me. It created that text file and when I open it, I see TEXT.

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 total points
ID: 35204265
btw ... this can be simplified to this:

    Dim fns As String
    fns = "c:\List.txt"
   
    Dim fso As FileSystemObject
   
    Set fso = CreateObject("Scripting.FileSystemObject")
    With fso.CreateTextFile(fns, True)
       .WriteLine ("This is a test.")
       .Close
    End With
  Open fns For Output As #3
  Write #3, "TEST this is working"
  Close #3
 
... with the added advantage that you get Intellisense after typing the DOTS ...

btw ... when I say working, it writes the 'This is a test" first ... then TEST this is working ...

mx
Capture1.gif
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 1

Author Comment

by:CipherIS
ID: 35204403
When I say its not working I mean that C:\List.txt is not being created and as a result no text is in the file.

That is the problem I'm experiencing.  I am using MS Access 2007 on Win7 computer.
0
 
LVL 75
ID: 35204407
Well ... it is certainly working for me.  I have noticed however that if ... some error occurs (like the file is already open) ... the error seems to be 'silent'. So, apparently some error is occurring on your system.  Not sure why it's not being rendered (the error that is).  Maybe some permissions / UAC issue with Win 7 ... or, is your db in a Trusted Location ?

mx
0
 
LVL 1

Author Comment

by:CipherIS
ID: 35204411
db is on my client.

I put set warnings = true but no errors are being generated and error handling is not catching anytghing.,
0
 
LVL 1

Author Comment

by:CipherIS
ID: 35204427
ok - it is creating the file but it is storing it at

C:\Users\Admin\AppData\Local\VirtualStore

Any idea how to get it to create on the "C:\" Drive?
0
 
LVL 75
ID: 35204434
Actually, it appears there is no error if the file is open ... it actually replaces the text (I changed the text). So far, I cannot really force an error.

mx
0
 
LVL 1

Author Comment

by:CipherIS
ID: 35204435
So it seems if I have a dir "C:\Test\" it will create it there but not on C:\ drive

any ideas?
0
 
LVL 75
ID: 35204437
wow.  let me try this on my Win 7 machine ...

mx
0
 
LVL 75
ID: 35204494
Well, on my Win 7 System (A2010), it puts the file in C:\ .... so ...

mx
0
 
LVL 77

Expert Comment

by:peter57r
ID: 35205286
The default position for Win7 (as it was for Vista) is that you can't save into c:\.  End-users would normally be running machines with this restriction in place.


Developers tend to disable any security settings, or run with sufficient admin rights to overcome things that stop them doing what they want so we don't see the problem.

To broaden the issue you will find that in WIn 7 there are lots of folders that could be accessed directly in previous versions of windows which are now inaccessible and map to virtual locations.

0
 
LVL 1

Author Comment

by:CipherIS
ID: 35206519
ok - so I will save to another location can you tell me how to modify the code so it opens the file once its done writing to it?
0
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 1000 total points
ID: 35208861
Assuming fns contains the full path then you can just do..

Application.Followhyperlink fns

This will open the file in whatever is the associated applicaton for .txt files (usually Notepad)
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question