AdoRequery




Public Sub ADO_OpenRs(rs As Recordset, szSource$, Optional bReadOnly = False)
' Open or Requery a Recordset.

On Error Goto lab_Err

If rs.State = adStateClosed Or rs.Source <> szSource Then
If rs.State <> adStateClosed Then rs.Close
rs.Open szSource, gCn, adOpenStatic, IIf(bReadOnly, adLockReadOnly, adLockOptimistic)
Else
rs.Requery
End If
lab_Exit:

Exit Sub

lab_Err:

MsgBox Err.Description
Goto lab_Exit

End Sub
It requires a public ADODB.Connection - I call it gCn.
The routine will open a new recordset (compatible with Janus GridEx),
or refresh it if it's open or if the SQL has changed.
Optional ReadOnly argument.

A basic ADO Open and Requery routine
By: Steve Mann

Inputs:

rs - an ADO recordset
(eg Dim rsMine as New ADODB.Recordset)

szSource - (eg "select * from customers")
Optional - bReadOnly (True For read-only)

Returns:Sets the supplied Recordset.

Assumes:Assumes your public ADO Connection object is
called gCn, and that the supplied szSource is a valid
SQL statement.











( adorequery.html )- by Paolo Puglisi - Modifica del 17/12/2023