Creating a .txt file that contains the test in a field

G

Guest

Hello:
i am trying to extract the information from an Access database field (Memo
type).
This is in a database of my CDs and this field contains the lyrics to some
songs.
I want to extract this field and put it into a txt file or the form "Artist
- song".txt

i think this can be done with SQl, but I cannot figure it out.
 
G

Graham Mandeno

Hi Mark

It can't be done using SQL, but it can using VBA.

You need to open the file for output (which will create it), write the text
to the file, and then close it

Let's say you have a form open with textboxes bound to the fields for
Artist, SongTitle, and Lyrics. Something like this should work:

Dim hFile as Long
Dim sFileName as string
sFilename = CurrentProject.Path & "\" & Artist & " - " & SongTitle & ".txt"
hFile = FreeFile
Open sFileName for output as #hFile
Print #hFile, Lyrics
Close #hFile
 
G

Guest

Thank you Graham. I appreciate the help. I figured it could be done, but I
was not sure how to do it.

Graham Mandeno said:
Hi Mark

It can't be done using SQL, but it can using VBA.

You need to open the file for output (which will create it), write the text
to the file, and then close it

Let's say you have a form open with textboxes bound to the fields for
Artist, SongTitle, and Lyrics. Something like this should work:

Dim hFile as Long
Dim sFileName as string
sFilename = CurrentProject.Path & "\" & Artist & " - " & SongTitle & ".txt"
hFile = FreeFile
Open sFileName for output as #hFile
Print #hFile, Lyrics
Close #hFile

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

markshunter said:
Hello:
i am trying to extract the information from an Access database field (Memo
type).
This is in a database of my CDs and this field contains the lyrics to some
songs.
I want to extract this field and put it into a txt file or the form
"Artist
- song".txt

i think this can be done with SQl, but I cannot figure it out.
 
G

Guest

I have tried to do some reading up on how to put htis in, but I am having
some trouble firguring out where the VBA code goes. I am realtively new to
this. I aplogize in advance.

If you could give me a quick newvie lesson on where the VBA code goes, that
would be helpful.

Thanks...

Graham Mandeno said:
Hi Mark

It can't be done using SQL, but it can using VBA.

You need to open the file for output (which will create it), write the text
to the file, and then close it

Let's say you have a form open with textboxes bound to the fields for
Artist, SongTitle, and Lyrics. Something like this should work:

Dim hFile as Long
Dim sFileName as string
sFilename = CurrentProject.Path & "\" & Artist & " - " & SongTitle & ".txt"
hFile = FreeFile
Open sFileName for output as #hFile
Print #hFile, Lyrics
Close #hFile

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

markshunter said:
Hello:
i am trying to extract the information from an Access database field (Memo
type).
This is in a database of my CDs and this field contains the lyrics to some
songs.
I want to extract this field and put it into a txt file or the form
"Artist
- song".txt

i think this can be done with SQl, but I cannot figure it out.
 
G

Graham Mandeno

Hi Mark

Where you put the code depends on whether you want to process one song at a
time, as required, or do a whole lot in batch.

Let's assume it's the former. If you have a form bound to your song table,
with textboxes bound to the Artist, SongTitle, and Lyrics fields (substitute
your own names here) then you can add a command button, cmdCreateTextFile,
and put this code in its Click event procedure:

Private Sub cmdCreateTextFile_Click()
<code goes here>
End Sub
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MarkSHunter said:
I have tried to do some reading up on how to put htis in, but I am having
some trouble firguring out where the VBA code goes. I am realtively new
to
this. I aplogize in advance.

If you could give me a quick newvie lesson on where the VBA code goes,
that
would be helpful.

Thanks...

Graham Mandeno said:
Hi Mark

It can't be done using SQL, but it can using VBA.

You need to open the file for output (which will create it), write the
text
to the file, and then close it

Let's say you have a form open with textboxes bound to the fields for
Artist, SongTitle, and Lyrics. Something like this should work:

Dim hFile as Long
Dim sFileName as string
sFilename = CurrentProject.Path & "\" & Artist & " - " & SongTitle &
".txt"
hFile = FreeFile
Open sFileName for output as #hFile
Print #hFile, Lyrics
Close #hFile

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

markshunter said:
Hello:
i am trying to extract the information from an Access database field
(Memo
type).
This is in a database of my CDs and this field contains the lyrics to
some
songs.
I want to extract this field and put it into a txt file or the form
"Artist
- song".txt

i think this can be done with SQl, but I cannot figure it out.
 

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