ADODB Enter your connection string??? Do I need a reference to runit?

R

rebelscum0000

Dear all

I have this code

First I want to know if I need to check any reference to work with
ADODB if yes which one?

Second what is please enter my connection string?

Thanks in advance for any help you can provide me

Regards,
Antonio Macias

Sub WriteToTextFile()

Dim rs As New ADODB.Recordset
Dim dbCon As New ADODB.Connection
Dim fnum As Integer

dbcon.Open (<please enter your connection string>)

rs.Open "Select DirHashFiles From TempData_Tbl", dbCon

fnum = FreeFile()


If rs.BOF = False Then

'open the text file
Open " c:\test.txt" For Output As #fnum

rs.MoveFirst
Do Until rs.EOF

Print #fnum, DirHashFiles


rs.MoveNext
Loop

End If

End Sub
 
D

Dirk Goldgar

rebelscum0000 said:
Dear all

I have this code

First I want to know if I need to check any reference to work with
ADODB if yes which one?

Second what is please enter my connection string?

Thanks in advance for any help you can provide me

Regards,
Antonio Macias

Sub WriteToTextFile()

Dim rs As New ADODB.Recordset
Dim dbCon As New ADODB.Connection
Dim fnum As Integer

dbcon.Open (<please enter your connection string>)

rs.Open "Select DirHashFiles From TempData_Tbl", dbCon

fnum = FreeFile()


If rs.BOF = False Then

'open the text file
Open " c:\test.txt" For Output As #fnum

rs.MoveFirst
Do Until rs.EOF

Print #fnum, DirHashFiles


rs.MoveNext
Loop

End If

End Sub


To run that code, you need to have a reference set to the Microsoft ActiveX
Data Objects 2.x Library. Which sub-version number ("x") depends on what
happens to be installed on your computer. You mnay have more than one
version. If you're developing your database for your own use, you'll
probably want to pick the latest version.

Where it says "<please enter your connection string>" is where you would put
the connection string to access your database. A connection string is a
text string that defines the source database and the way that the ADO
Connection object will connect to it.

If you're running this code in the Access database that contains the table
"TempData_Tbl", though, you don't need to open a new connectionl; you can
use the one that Access is using. To do that, you would replace these
lines:
Dim dbCon As New ADODB.Connection
dbcon.Open (<please enter your connection string>)

with these:

Dim dbCon As ADODB.Connection

Set dbcon = CurrentProject.Connection
 
R

rebelscum0000

Hi Dirk

Well, I will check Microsoft ActiveX Data Objects 2.8 Library for now

I am getting these errors, what I am doing wrong?

Run-time error '52'
Bad file name or number

and then

Run-time error '55'
File already open


Sub WriteToTextFile()

'Reference
'Microsoft ActiveX Data Objects 2.8 Library.

Dim rs As New ADODB.Recordset
Dim dbCon As ADODB.Connection
'Dim dbCon As New ADODB.Connection
Dim fnum As Integer

Set dbCon = CurrentProject.Connection
'dbcon.Open (<please enter your connection string>)


rs.Open "Select DirHashFiles From TempData_Tbl", dbCon

fnum = FreeFile()


If rs.BOF = False Then

'open the text file
Open " c:\test.txt" For Output As #fnum

rs.MoveFirst
Do Until rs.EOF

Print #fnum, DirHashFiles


rs.MoveNext
Loop

End If

End Sub

Thanks in advance
Regards
Antonio Macias
 
D

Dirk Goldgar

rebelscum0000 said:
Hi Dirk

Well, I will check Microsoft ActiveX Data Objects 2.8 Library for now

I am getting these errors, what I am doing wrong?

Run-time error '52'
Bad file name or number

and then

Run-time error '55'
File already open


First, make sure that the code closes the file if it opens it. I'd suggest
a modification like this:

'----- start of revised code -----
Sub WriteToTextFile()

'Reference
'Microsoft ActiveX Data Objects 2.8 Library.

Dim rs As New ADODB.Recordset
Dim dbCon As ADODB.Connection
'Dim dbCon As New ADODB.Connection
Dim fnum As Integer

On Error GoTo Err_Handler

Set dbCon = CurrentProject.Connection
'dbcon.Open (<please enter your connection string>)

rs.Open "Select DirHashFiles From TempData_Tbl", dbCon

fnum = FreeFile()

If rs.BOF = False Then

'open the text file
Open "c:\test.txt" For Output As #fnum

rs.MoveFirst
Do Until rs.EOF

Print #fnum, DirHashFiles

rs.MoveNext
Loop

End If

Exit_Point:
Close
Exit Sub


Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Sub
'----- end of revised code -----

I think that should take care of the error 55 (File already open), which
probably happened in the course of debugging.

I suspect that your error 52 (Bad file name or number) was caused by the
leading space you had in the file path you gave in your Open statement. You
wrote:
Open " c:\test.txt" For Output As #fnum

where you should have had:

Open "c:\test.txt" For Output As #fnum

That said, I think even after you fix that you may get a permissions error
when you try to open the file, depending on what version of Windows you are
running. I know that Vista won't let me write to the root directory of my
C: drive, so the above statement raises error 75 for me, whereas this works
fine:

Open "C:\Users\Dirk\Documents\test.txt" For Output As #fnum
 
R

rebelscum0000

Hi

Well, first at all

I am working under windows xp pro w/sp2 with all the latest updates
And Access 2003 w/SP2 also with the latest updates, I still do not
want to Install SP3 I have read the pacth still have problems...


I did the following
New Query in design view, SQL view and entered
Select DirHashFiles From TempData_Tbl
Finally Run
The tbl TempData_Tbl has 186 records

When I run the code you provide me I do not have any execution
problem, the .txt file is created but blank, no records, no data to
read

I have a similar problem like this post

http://groups.google.com/group/micr...77e0e/add6e070f44d1de4?hl=en#add6e070f44d1de4

The strange thing is the code Writes out a Temporal Report TXT file

'Writing out a Temporal Report TXT file:
'<Drive>:\<Drive> Report.txt OR
'<Drive>\Folder\FirstFolder Report.txt OR
'<Drive>:\Folder\Folder...\<Drive> FirstFolder TO LastFolder
Report.txt
'In order to add this file into the Hash File without user
intervention (Writing out a Temporal batch file)

Open TempTXTFile For Output As #egfFF
Print #egfFF, "============ 00/00/0000 00:00:00 AM/PM
============"
Print #egfFF, "-- Results --"
Print #egfFF, "Info"
Print #egfFF, "- date: 00/00/0000"
Print #egfFF, "- process: Hash"
Print #egfFF, "- source: <Drive>:\<Folder>"
Print #egfFF, "- source volume label: Volume Name"
Print #egfFF, ' Write blank line.
Print #egfFF, "Basic statistics"
Print #egfFF, "- time elapsed: 00:00:00"
Print #egfFF, "- overall transfer [kB/s]:
000000000000,000000000000"
Print #egfFF, "- folders processed: 000000000000"
Print #egfFF, "- files processed: 00000000000000"
Print #egfFF, "- source bytes read: 000000000000 MB
(000000000000,000000000000,000000000000 bytes)"
Print #egfFF, "- source average transfer [kB/s]:
000000000000,000000000000"
Print #egfFF, "- source clean transfer [kB/s]:
000000000000,000000000000"
Print #egfFF, ' Write blank line.
Print #egfFF, "Errors"
Print #egfFF, "- errors: 000000000000"
Print #egfFF, "- warnings: 0000000000"
Print #egfFF, "- other: 0000000000000"
Print #egfFF, ' Write blank line.
Print #egfFF, "-- Messages --"
Print #egfFF, "note;hash;Hash file created (code:
0000000000000);<Drive>:\<Folder>:\File.CRC"
Print #egfFF, "note;hash;Hash file created (code:
0000000000000);<Drive>:\<Folder>:\File.CRC"
Print #egfFF, "note;hash;Hash file created (code:
0000000000000);<Drive>:\<Folder>:\File.CRC"
Close #egfFF ' Close file.

-|The code Also writes a batch file

'Initialize New Event Writing_out_batch_file_CDCheck
'Initialize Variables

amcFF = FreeFile()

'Writing out a batch file (.bat or .vbs) using VBA
'Working and Tested Solution
'Determine IF is <Drive>:\ OR <Drive>:\Folder OR <Drive>:\Folder
\Folder...
'Please note: Very Sensitive if the user opens a file the hash
change
If MyCodeSelection = 1 Then

Open "C:\Program Files\Dups\Batch Files\HashIt.bat" For
Output As #amcFF
Print #amcFF, "CD /D " & Chr(34) & Environ("ProgramFiles")
& "\CDCheck" & Chr(34)
Print #amcFF, "START /WAIT CDCheck /CRC:MD5 " & Chr(34) &
GetFolder & Chr(34) & Chr(32) & _
"/O:" & Chr(34) & GetFolder & strDrive & ".CRC" & Chr(34)
& Chr(32) & _
"/SaveReport:" & Chr(34) & GetFolder & strDrive & "
Report" & ".txt" & Chr(34)
Close #amcFF

ElseIf MyCodeSelection = 2 Then

Without any problem

-|But with the code you provide

Sub WriteToTextFile()


'Reference
'Microsoft ActiveX Data Objects 2.8 Library.


Dim rs As New ADODB.Recordset
Dim dbCon As ADODB.Connection
'Dim dbCon As New ADODB.Connection
Dim fnum As Integer


On Error GoTo Err_Handler


Set dbCon = CurrentProject.Connection
'dbcon.Open (<please enter your connection string>)


rs.Open "Select DirHashFiles From TempData_Tbl", dbCon


fnum = FreeFile()


If rs.BOF = False Then


'open the text file
Open "c:\matias.txt" For Output As #fnum


rs.MoveFirst
Do Until rs.EOF


Print #fnum, DirHashFiles


rs.MoveNext
Loop


End If


Exit_Point:
Close
Exit Sub


Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point


End Sub

I Still don't getting the result I need

What I am doing wrong????????

Please help!

Regards,
Antonio Macias
 
D

Dirk Goldgar

rebelscum0000 said:
But with the code you provide

Hey, I only provided some modifications to a couple of specific lines of
that code. Don't blame me for the others!

It looks to me like this line is probably at fault:
Print #fnum, DirHashFiles

Without any qualification by the recordset object, DirHashFiles is going to
be interpreted as an undeclared Variant variable, with an initial value of
(Empty). Unless you have Option Explicit stated at the top of your module,
that won't raise an error, but it will print out blank on every line of the
text file.

That line should be:

Print #fnum, rs!DirHashFiles

See if that makes a difference.

I *strongly* recommend setting your VB options to "Require Variable
Declaration", so that Option Explicit is automatically placed at the top of
every new module you create. And you should go back and put Option Explicit
at the top of every existing module, if it isn't already there.
 
R

rebelscum0000

Hey, I only provided some modifications to a couple of specific lines of
that code.  Don't blame me for the others!

Yes, you are right, please accept my excuse

I will try the same code in Access 2002 w/SP3 I do not know what is
wrong
the code runs fine but now I do not get a blank .txt file, now the
text file has squares and squares and square..

Do you know why is doing this or when in a recodset when is reading
line by line and writes squares? any idea?

Regards,
Antonio Macias
 
D

Dirk Goldgar

I woud check the value of the data you are writing to the the file. You
should be able to step through the code line by line in debug mode and
examine the value of rs!DirHashFiles to see what it contains. What data
type is this field?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Hey, I only provided some modifications to a couple of specific lines of
that code. Don't blame me for the others!

Yes, you are right, please accept my excuse

I will try the same code in Access 2002 w/SP3 I do not know what is
wrong
the code runs fine but now I do not get a blank .txt file, now the
text file has squares and squares and square..

Do you know why is doing this or when in a recodset when is reading
line by line and writes squares? any idea?

Regards,
Antonio Macias
 
R

rebelscum0000

I woud check the value of the data you are writing to the the file.  You
should be able to step through the code line by line in debug mode and
examine the value of rs!DirHashFiles to see what it contains.  

How?
Debug.Print rs!DirHashFiles?

What data type is this field?

Somerhing like

DirHashFiles
[Data]
C:\Program Files\Ahead\
453372791bf6334e4868bc0fce40518a C Program Files TO Ahead Report.txt
d41d8cd98f00b204e9800998ecf8427e C Program Files TO Ahead Temp.CRC
C:\Program Files\Ahead\CoverDesigner\
2adf3cb14186039d275b510452f13bb5 CoverDes.exe
eccc7c168428f9fe6e6c0ea2180770b9 CoverEdCtrl.ocx
520f42d974578eccb220a4e151e6928b def.dat
9e0dc7bae6024c0da57749bd2ad3877e NeroCoverDesigner_eng.chm
ec6828dcfe9746644cfa3b429440de5e stocks.dat

And the Data Type is Text

I tried the same code in Windows XP Home Edition W/SP2 Spanish Version
update with all the services pack until now
Office 2002 w/SP3 English Version with all the updates until now
and I get the same result

I think this is something very simple in fact I did this convertion
several times in the past, but now I do not know what or where is the
problem

Please help!

TIA
Regards,
Antonio Macias
 

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