What you need is :-
Code:
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockPessimistic
rst.Open "SELECT etc.. .."
' Clever code in here
rst.Close
rst.ActiveConnection sets up the connection and as you are connecting to a table in the current database then you can use "CurrentProject.Connection "
rst.CursorType = adOpenKeyset
rst.LockType = adLockPessimistic
The rst.Open line is usually show in the example code in help files containing all of the Connection, Cursor, Lock etc info all in one line.
It does not have to be.
To my mind laying it out as above makes it easier to read and hence debug.
If all the other parameters are pre-set - then the rst.Open line just needs to contain the SQL string that defines the recordset.
rst.Open "SELECT etc.. .."
Then don't forget to
rst.Close
when you've finished with it.
By doing it this way you can re-use the same Recordset object with different recordsets in one module.
eg.
..
all the lines before rst.Open then
rst.Open "SELECT * FROM tbl1 etc First recordset
' Your first lot of work
rst.Close
rst.Open "SELECT * FROM tbl2 etc Secord recordset
' Your second lot of work
rst.Close
rst.Open " SELE .. etc.
You don't need to re-set the
rst.Connect.. ..
rst.Lock.. ..
rst.Cursor.. ..
'ope-that-'elps
G LS