By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,775 Members | 2,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,775 IT Pros & Developers. It's quick & easy.

FORM to TXT, Query to TXT, current form to text file

P: 91
Hello Access Guru's

After pulling out most of my hair last year getting access to work the way I wanted it to to perform the simplest tasks, I am back at it and aim to not to pull out the rest!

What I am Aiming for
» I have a FORM that has a Query as its source.
» I want to create a cmd button on the form that exports the data on the current form to a txt file and then opens the or a txt file that has certain textbox values from the current form. ( reason for the form data is some of the texbox's have combined info from more then one textbox controls on form... for instance

Expand|Select|Wrap|Line Numbers
  1. Me.txtImageUrl = [txtImageHttp] & "" & Left([txtImageId], 3) & "/" & [txtImageId] & "" & [txtJpg]
» data in txt file is formatted in a way where each field value is on a separate line or | delimited.. you know, so it looks nice, nut just a dump seperated by commas,,,,
» More then one solution would be cool..
» and ah yes, Keep it simple.

thanks you guys are great.. M@
Feb 10 '09 #1
Share this Question
Share on Google+
8 Replies

Expert 100+
P: 489
As a start you could look at the OpenTextFile and OpenAsTextStream methods. Also check out the #write and #print statements.
Feb 10 '09 #2

P: 91 » #print AND #write

yields all sorts of results... im starting to reach for my hair.

Examples anyone?

Feb 11 '09 #3

Expert 100+
P: 489
Here is a quick example on how to use #print

Expand|Select|Wrap|Line Numbers
  1. Dim stName As String
  2. stName = "c:/test.txt"
  3. Open stName For Output As #1
  4. Print #1, Me.TextBox1
  5. Print #1, Me.TextBox2
  6. Print #1, Me.Textbox3
  7. Close #1
And #Write

Expand|Select|Wrap|Line Numbers
  1. Dim stName As String
  2. stName = "c:/test.txt"
  3. Open stName For Output As #1
  4. Write #1, Me.TextBox1
  5. Write #1, Me.TextBox2
  6. Write #1, Me.Textbox3
  7. Close #1
The #write will include quotes around the text and the #print won't. However I believe that with the #print there may be times that you need to do a Ltrim() to remove leading space. Replace the "Output" part with "Append" If you want to append to the end of an existing file.
Feb 11 '09 #4

P: 91

Very Cool, Very cool...

one more question,
It worked, but data is dumped and all scrunched together..
How would I add or rather insert a, lets say a return, <p></p>, line space if you may between each line? or a separator like --------------------
like this

contents of TextBox1
contents of TextBox2

contents of TextBox3

Or better yet, like this

NAME: | contents of TextBox1
ADDRESS: | contents of TextBox2

EMAIL | contents of TextBox3

AND what line of code would I use to open the Test.txt file after it exports?

thank you so much,
Feb 12 '09 #5

P: 91
Hello All Figured some out on my own by searching this forum this way in google. ► site: "Open File"

here is the Code so far

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdToText_Click()
  2. Dim stName As String
  3. Dim stOpenIt As String
  4.     stName = "C:\matt.txt"
  5.     Open stName For Output As #1
  6.     Print #1, "Name | ", Me.txtName
  7.     Print #1, Me.txtAddress
  8.     Print #1, "------------------------"
  9.     Print #1, Me.txtPhone
  10.     Print #1, Me.txtEmail
  11.     Print #1, ""
  12.     Close #1
  13.     OpenIt = Shell("C:\WINDOWS\Notepad.EXE C:\matt.txt", 1)
  14. End Sub
It works!!!

Print #1, "" ( inserts a Line )
Print #1, "------------------------" ( you guess it )
Print #1, "Name | ", ( puts text in front of Me.txtName.. like so» Name | Matt )
Declaring stOpenIt and then this line opens the text file
OpenIt = Shell("C:\WINDOWS\Notepad.EXE C:\matt.txt", 1)

All Right!!!
Hope this helps someone
Feb 12 '09 #6

Expert 100+
P: 489
I'm glad you got it working, Just let us know if we can supply you with any more help.
Feb 12 '09 #7

Expert 100+
P: 1,287
This may be helpful also: Print and Display Constants. I just found it and I bookmarked it.
Feb 12 '09 #8

Expert Mod 15k+
P: 31,417
You're using Print#. The Help topic gives some helpful techniques for this, and how best to understand what it's doing (limitations etc).

A few very basic tips :
  • The outputlist parameter(s) can be separated by a comma (,) or a semi-colon (;).
  • The comma will space out to the next tab position before printing the next data.
  • The semi-colon ensures no separation.
  • Unless there is a trailing semi-colon, a new line (vbCrLf) is always appended (Print #1 on its own simply adds a new line).
Feb 16 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.