Access.2007.VBA.Bibl..

(John Hannent) #1
TABLE 5.5

ADO Recordset Lock Type Named Arguments


Lock Type Named Constant Numeric Value

Read-only adLockReadOnly 1
Optimistic adLockOptimistic 3
Batch Optimistic adLockBatchOptimistic 4
Pessimistic adLockPessimistic 2

Sometimes the ADO recordset that is created is not the type you specify in the
CursorType argument, depending on the lock type. In particular, if you specify the
adLockOptimisticlock type for any cursor type, you will actually get a Keyset cursor. To deter-
mine the actual recordset type, use the following statement (see Table 5.4 to convert the numeric
type to its matching named constant):

Debug.Print “Recordset cursor type: “ _
& rst.CursorType

For a more advanced determination of the actual cursor type and lock type of a newly created
recordset, run the following procedure, substituting the desired cursor and lock type in the
rst.Openline:

Private Sub TestMethodsSupported()

On Error Resume Next

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strDBName As String
Dim strConnectString As String
Dim strSQL As String
Dim strCursorType As String
Dim strLockType As String
Dim strCurrentPath As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim strDBNameAndPath As String
Dim strPrompt As String

Create a connection to an external database.
strCurrentPath = Application.CurrentProject.Path & “\”
strDBName = “Northwind.mdb”
strDBNameAndPath = strCurrentPath & strDBName

NOTENOTE


Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf