error opening database/table

lchurch
07-02-2007, 04:30 PM
I'm using this code:
' Export of RONotes
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\RONotes.MDB;"
MyConn.Open

MsgBox (MyConn.State)

Set MyRecSet = MyConn.Execute("SELECT * FROM SFtable")
MsgBox (MyRecSet.RecordCount)
.................................................
To open a database and get values from a table. The MyConn.state always shows "1", but MyRecSet.RecordCount always shows "-1". But this table has 2 rows that are populated.

What am I doing wrong?

DougT
07-02-2007, 11:19 PM
Try

MyRecset.Open ("SELECT * FROM SFtable",MyConn, adOpenStatic,adLockOptimistic)

See ..

lchurch
07-03-2007, 04:09 AM
That code produces and error of "=" expected, until I remove the parenths "()". Then I get an error on run that "object variable or with blcok variable not set".
I had also tried the code from the ADO tutorial, and it returns no records also:
Set MyRecSet = MyConn.Execute("SELECT * FROM SFtable"). Since I have conformed each time that the table is populated, it's very frustrating.

DougT
07-03-2007, 04:13 AM
My mistake, you need

Set MyRecSet = New RecordSet

prior to the Open

Shurik12
07-03-2007, 04:32 AM
To add up to what has been said:

to return a correct .RecordCount a recordset should support .AbsolutePosition and .Absolute page properties.
The way you were trying to open the recordset will result into forward-only cursor and the above mentioned properties won't be suppoted thus returning -1

You might want to have a look at the Support method
http://www.w3schools.com/ado/met_rs_supports.asp
and here too
http://www.w3schools.com/ado/prop_rs_recordcount.asp

lchurch
07-03-2007, 05:39 AM
That fixed it; thanks for the help and guidance.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum