V
Vayse
Hi
Just wondering what way people open their ADO recordsets.
Is one method better than another?
1) Dim an ADO connection
Dim cnnADO As ADODB.Connection
Dim rsSchedule As New ADODB.Recordset
Set cnnADO = CurrentProject.Connection
stSQL = "SELECT ScheduleID, ScheculeName FROM Schedule_Reports"
rsSchedule.Open stSQL, cnnADO, adOpenDynamic, adLockOptimistic
' Do stuff
rsSchedule.Close
cnnADO.Close
2) Use CurrentProject.Connection
Dim rsSchedule As New ADODB.Recordset
stSQL = "SELECT ScheduleID, ScheculeName FROM Schedule_Reports"
rsSchedule.Open stSQL, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
' Do stuff
rsSchedule.Close
I've been using method 1 for as long as I can remember, but now I'm starting
to wonder why.
Btw, in method 2,I don't close CurrentProject.Connection. I think I heard
somewhere before that one should leave this connection open?
Anyway, even if I try
CurrentProject.Connection.Close
the currentproject.Connection.State will stay at 1.
Thanks
Vayse
Just wondering what way people open their ADO recordsets.
Is one method better than another?
1) Dim an ADO connection
Dim cnnADO As ADODB.Connection
Dim rsSchedule As New ADODB.Recordset
Set cnnADO = CurrentProject.Connection
stSQL = "SELECT ScheduleID, ScheculeName FROM Schedule_Reports"
rsSchedule.Open stSQL, cnnADO, adOpenDynamic, adLockOptimistic
' Do stuff
rsSchedule.Close
cnnADO.Close
2) Use CurrentProject.Connection
Dim rsSchedule As New ADODB.Recordset
stSQL = "SELECT ScheduleID, ScheculeName FROM Schedule_Reports"
rsSchedule.Open stSQL, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
' Do stuff
rsSchedule.Close
I've been using method 1 for as long as I can remember, but now I'm starting
to wonder why.
Btw, in method 2,I don't close CurrentProject.Connection. I think I heard
somewhere before that one should leave this connection open?
Anyway, even if I try
CurrentProject.Connection.Close
the currentproject.Connection.State will stay at 1.
Thanks
Vayse