Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficulty in getting the recordset correct 1

Status
Not open for further replies.

sidharthrshah

Programmer
Jun 21, 2003
5
0
0
IN
I have the code for converting an access database to comma delimited file.But it requires recordset that has to be exported and I have to open the recordset before passing it to this function.So how do I do this?

I want all the fields of the table 'sidtable' in recordset.
the table fields are : nam,telno,addr
the access file name is collproj.mdb

Any kind of help will be highly appreciated.
Thanks,
Sidharth.
------------------------------------------------------------

Public Function RecordsetToText(rs As Object, Optional FullPath _
As String, Optional ValueDelimiter As String = " ") As Boolean

'PURPOSE: EXPORTS DATA FROM AN ADO RECORDSET TO A TEXT FILE

'PARAMETERS:

'RS: Recordset to Export. Open the recordset before
'passing it to this function

'FullPath (Optional): FullPath of text file.
'if not specified, the function uses app.path +
'rs.txt

'ValueDelmiter (Optional): String to delimiter
'values within a row. If not specified, an empty space
'is used

'RETURNS: True if successful, false if an error occurs

'COMMENTS: Rows are delimited by a carriage return
---------------------------------------------------------
I added the following function but it gives the following error :
Runtime Error '3001':

Arguments are of the wrong type,are out of the acceptab;e range,or are in conflict with one another.

Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\nimeet\collproj.mdb"
cn.Open
Set rs = cn.OpenRecordset("sidtable")
RecordsetToText rs, "C:\My Documents\nimeet\sidtable.txt", ":"
End Sub
 
>I added the following function but it gives the following error :
Runtime Error '3001':

Where does it give this error? Please be specific!


I would expect it at the line
Code:
RecordsetToText rs, "C:\My documents\nimeet\sidtable.txt", ":"
and the potential solution:
change
Code:
Public Function RecordsetToText(rs As Object, Optional FullPath _
  As String, Optional ValueDelimiter As String = " ") As Boolean
to
Code:
Public Function RecordsetToText(rs As ADODB.Recordset, Optional FullPath _
  As String, Optional ValueDelimiter As String = " ") As Boolean
[\code]

ADODB.Recordset is a type of object, but it isn't "Object" 

code

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 

Hi

Try putting the filename in single quotes within the string:
Code:
cn.ConnectionString = _
   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\My Documents\nimeet\collproj.mdb'"

Matt: Error 3001 is an ADO error. Passing the RecordSet as an object would not trip 3001.

Cassie
 
The error is given while executing the code and it gives error at the line :

Set rs = cn.OpenRecordset("sidtable")
 
having been slapped down (correctly) by cassie2002[\b] for not recognising the 3001 error, I am a little hesitant to jump in again...
My point about altering the definition is still valid though!

however here goes...

my version of ADODB (2.6) does not have an Openrecordset method of the connection object. I generally use

Set rs = cn.Execute("sidtable",,adcmdTable) to return a recordset.

try it!


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 


Oops! Now, it my turn to be slapped down (correctly). I missed the point that CCLINT pointed out.

Sorry, Matt, I meant no offense. Just wanted to help keep you on the right track.

Cassie
 
>Sorry, Matt, I meant no offense. Just wanted to help keep you on the right track.

Absolutely none taken, promise


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thank You Everyone for your time and help.My Problem has been solved by Matt.

Regards,
Sidharth.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top