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

I'm trying to open a record set

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
Using ADO:

Dim adoConnection As ADODB.Connection
Dim adoRecordset As ADODB.Recordset
Dim ConnectionString As String

Set adoConnection = New ADODB.Connection
Set adoRecordset = New ADODB.Recordset

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Highways\VB Projects\Project Files HWPE\CentralPhotoDatabase.mdb")
adoConnection.Open ConnectionString

If adoConnection.State = adStateOpen Then
MsgBox "CONNECTION OPEN!"
End If

adoRecordset.Open "Photos", adoConnection

The "CONNECTION OPEN!" message box comes up OK so I know that that bit works but when the last line executes VB complain that its expecting an SQL statement. On the MSDN site I've read that the first parameter CAN be a valid table name (incidently "Photos" IS the correct table name).

Any help???

thanks
 

adoRecordset.Open "SELECT * FROM Photos", adoConnection, adOpenKeyset, adLockOptimistic, adCmdText


Change the cursor type and the lock type to that suits you best.

David Paulson


 
The syntax for a recordset Open is:

recordset.Open Source, ActiveConnection, CursorType, LockType, Options

If you want Source to be a table, set the Options to adCmdTable or adCmdUnknown. If you want to update it, it is also important to set the LockType.

It's a lot more common to use a SQL statement.
 
hirick,

using your example I did the following:

adoRecordset.Open "Photos", adoConnection, , , adCmdUnknown

which gave the error: "Invalid SQL satement; expected 'Delete'.... etc."

dpaulson,

using your example I got the following error:

'The microsoft Jet database engine cannot find the input table or query 'Photos'. Make sure it exists and is spelt correctly.'

...which it it.

Thanks both of you, any chance of a bit more help?

elziko
 
Many, many apologies. I had two databases with very similar names. I used the wrong one. Its working OK now.

I am stupid. Nevermind.

elziko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top