How to read the data in a tbl and save the records in a .txt file?

R

rebelscum0000

Dear All

I want to read record by record in a tbl in order to save the records
in a .txt file
Not manually, there is not a fixed string

I have this code it was working I do not know what I am doing wrong

Thanks in advance for any help

Regards,
Antonio Macias

This is my code;

'Initialize New Event Primary_Main_Event
'Initialize Variables

DHFFF = FreeFile()

'Select Only the Records of the Field Name DirHashFiles
'From the Tbl TempData_Tbl

sQL1 = _
"SELECT TempData_Tbl.DirHashFiles " & _
"From TempData_Tbl; "

'sQL16 = _
'"SELECT TempData_Tbl.ID, TempData_Tbl.DirHashFiles " & _
'"From TempData_Tbl " & _
'"ORDER BY TempData_Tbl.ID;"

'Initialize Variables
'Determine the number of records that are in the Tbl TempData_Tbl
intk = DCount("*", "TempData_Tbl")
Debug.Print "number of records that are in the Tbl TempData_Tbl "
& intk

Debug.Print "strVerify " & strVerify

Open strVerify For Output As #DHFFF

Set amcdb = CurrentDb
Set amcrs = amcdb.OpenRecordset(sQL1, dbOpenDynaset)

For intl = 1 To intk

'DHFID = amcrs.Fields("ID")
DHF = amcrs.Fields("DirHashFiles")

Print #DHFFF, DHF

amcrs.MoveNext

Next intl

Close #DHFFF
amcrs.Close
amcdb.Close
Set amcdb = Nothing
 
D

Douglas J. Steele

Are you getting an error message? If so, what's the error? If you're not
getting an error, what's happening (and what do you want to be happening
instead)?
 
R

rebelscum0000

Hi Doug

Are you getting an error message? If so, what's the error?
The code creates the file
No records in the textfile
I do not get an error on execution

The data in the file is
㡣㈲ã£æ¹æ„¶â€°æ…ƒç²ç‘¥ç€®æ‘³à¨ã´ã¤µæ•¢æˆ¶æ‰¡ã•¢æ±ã€´æ˜¸ãœ¹ã¹æµ
until the end of the file

My immediate window is

GetFolder = C:\Test
there are 2 Items in this string
C:
Test

Drive = C
First Folder = Test
Last Folder = Test
IS <Drive>:\Folder
MyCodeSelection = 2
Batch File Exists: = False
Folder Does not exits
Folder Does not Exists
Open a Hash File in <Drive>:\Folder
Path to replace in the tbl for DIR C:\
Hash File to read is C:\Test\Test.CRC
number of records that are in the Tbl TempData_Tbl 496
strVerify C:\Test\Test Verification.txt

Thanks in advance for any help you can provide me

Regards
Antonio Macias
 
D

Douglas J. Steele

What's the data type of the field?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Hi Doug

Are you getting an error message? If so, what's the error?
The code creates the file
No records in the textfile
I do not get an error on execution

The data in the file is
????????????????????????
until the end of the file

My immediate window is

GetFolder = C:\Test
there are 2 Items in this string
C:
Test

Drive = C
First Folder = Test
Last Folder = Test
IS <Drive>:\Folder
MyCodeSelection = 2
Batch File Exists: = False
Folder Does not exits
Folder Does not Exists
Open a Hash File in <Drive>:\Folder
Path to replace in the tbl for DIR C:\
Hash File to read is C:\Test\Test.CRC
number of records that are in the Tbl TempData_Tbl 496
strVerify C:\Test\Test Verification.txt

Thanks in advance for any help you can provide me

Regards
Antonio Macias
 
R

rebelscum0000

What's the data type of the field?

of the field of the tbl is like:
DirHashFiles
C:\Test\
453372791bf6334e4868bc0fce40518a Test Report.txt
d41d8cd98f00b204e9800998ecf8427e Test Temp.CRC
C:\Test\Adobe I\Photoshop\V. CS2\
a0790cab5214f42b7b92b66bcf869447 Activation Read Me.html
765ddeb65e8f58d2b9b090366b3c66f7 AUTORUN.INF
ac3e4579ff054573454832b34ee1a1d4 Creative Suite Brochure.pdf
8cbba32649ac4bd4fb1dfc860edf24a3 epic_eula.dll
bfefbee16ef9e695dc27c97fae224d50 How To Install.html
cc3a588ddb5a82ae5927b2694cb2999c LegalNotices.pdf
d1a2cce85a4e386f599688888b704d29 Photoshop At A Glance.pdf
33c5ab70a0c4bcb8fd91763ee4de9126 Photoshop New Features.pdf

Thanks in advance for any help you can provide me

Regards,
Antonio Macias
 
D

Douglas J. Steele

You're trying to write the contents of the DirHashFiles field in table
TempData_Tbl.

What is the data type of DirHashFiles defined as? If it's text, then I don't
know why your code doesn't work. If it's something else, then you'll need to
format it to something recognizable.
 
R

rebelscum0000

What is the data type of DirHashFiles defined as?

Yes, the data type of DirHashFiles is defined as text

Let's do something can you be so kind to provide an example of a code
that
reads a tbl record by record writing a txt file, using FreeFile, maybe
I am Dim wrong
or I am not closed the recordset they way it should be, something I
have to find out
and I will let you know what was wrong

Thanks in advance

Regards,
Antonio Macias
 
D

Douglas J. Steele

Your code looked fine to me.

If "record by record" you actually mean "line by line"

Dim intFile As Integer
Dim strFile As String
Dim strBuffer As String

strFile = "C:\Folder\File.ext"
intFile = FreeFile()
Open strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strBuffer
' Do something with strBuffer, which will be a line from the file.
Loop
Close #intFile
 

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