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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAO 3.6

Status
Not open for further replies.

LegoPiece

Programmer
Mar 19, 2001
95
US
I can't open a recordset!!! I wonder why - here's what I did...

Private Const DBFile = "C:\TestDB\DB.mdb"
Private Const SQLString = "Select * FROM Product;"
Private RS as new Recordset
Private DB as Database

Private Sub Form_Load()

Set DB = Workspaces(0).OpenDatabase(DBFile) 'This works
Set RS = DB.OpenRecordset(SQLString)

End Sub

This doesn't work, because I get a type mismatch! When I used to use DAO 3.51, the first parameter for the OpenRecordset method was [source], where the path of the Access file was entered. Now, it's asking for a [Name] property, and I'm certain that's why I'm getting the type mismatch. Now, if the method is called OPEN RECORDSET, and the return value is a RECORDSET... um.... why won't it allow me to send it the dumbest, simplest SQL string on this very planet????

Any help would be appreciated! Peace
Lego

"I don't think we have the right or the wisdom to interfere with an alien tribe no matter how it's evolving!" - Captain James T. Kirk

"Your people must embrace these words and the words that follow, for their true meanings are..." - Captain James T. Kirk (same episode)
 
In the following line,

Set RS = DB.OpenRecordset(SQLString)

you did not specify a cursor type. The default cursor is dbOpenTable, thus expecting a Table-Type recordset, in which an SQL statmenent is invalid as the source.

You should be able to solve this by specifying a specific type of cursor.

Set RS = DB.OpenRecordset(SQLString, dbOpenDynamic)
or some other cursor type.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Hi Cajun,

Hope it's going great! Unfortunately, specifying a cursor type in the argument didn't work either. I got a runtime error 3001, stating an "Invalid Argument". Here is the actual code, cut and pasted from my project. (cmbOperations is a Combo box btw).
--------------
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Const DBFile = "C:\motodemo\time entry\database\timekeeping.mdb"
Private Const SQLString = "SELECT * FROM Operation"
Private RS As New Recordset
Private DB As Database

Private Sub Form_Load()
'-------------------------------------------------------

Set DB = Workspaces(0).OpenDatabase(DBFile)
Set RS = DB.OpenRecordset(SQLString, dbOpenDynamic)

With RS
'.........................................................
While Not .EOF
cmbOperations.AddItem RS.Fields(1)
RS.MoveNext
Wend
'.........................................................
End With
'-------------------------------------------------------------
End Sub

Yep, this is a weird one, all right - I'm sure it's something pretty simple and obvious, which I'm neglecting - but for the life of me, I don't see why it's not working!

Thanks Again Peace
Lego

"I don't think we have the right or the wisdom to interfere with an alien tribe no matter how it's evolving!" - Captain James T. Kirk

"Your people must embrace these words and the words that follow, for their true meanings are..." - Captain James T. Kirk (same episode)
 
I think I would do a couple of things. First, insure that you have a reference to the Microsoft DAO Object Library in the project. Second, I would insure that my Database and RecordSet object are DAO types

Private RS As New DAO.Recordset
Private DB As DAO.Database

I would also move this code out of the Form Load event. I really do not like to do anything but simple initializations in Form_Load

Then I would try using dbOpenForwardOnly as my cursor type.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Hey Cajun,

Thanks a lot for the insights - I finally got it working after trying a few things you suggested. It turned out that I had a couple of references to ADO, which I removed. I then reverted back to using DAO 3.51, after converting the Access 2000 DB into '97 format (which 3.51 doesn't mind working with).

Thanks Again~! Peace
Lego

"I don't think we have the right or the wisdom to interfere with an alien tribe no matter how it's evolving!" - Captain James T. Kirk

"Your people must embrace these words and the words that follow, for their true meanings are..." - Captain James T. Kirk (same episode)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top