ADO Open Method

Home | About me | EXCEL VB Programming (XL97-2003) | ACCESS Programming | EXCEL VB.Net Programming | EXCEL Spreadsheet Functions Material Management  |  Guestbook
 

ADO Record Object: Open Method

The Open method opens a connection to a data source or is used to create a new file or directory. When the connection is open, you can execute commands against the data source.

Syntax


recordobject.Open Source, ActiveConnection, Mode, CreateOptions, Options, UserName, Password

 
Parameter Description
Source Optional. The source parameter may be one of the following:
  • An absolute url
  • A relative url
  • An open Recordset
  • Another Record object
  • A Command object
  • An SQL SELECT statement
  • A table name
ActiveConnection Optional. A connection string or a Connection object
Mode Optional. A ConnectModeEnum value, that indicates the access mode of the Record object. Default is adModeUnknown
CreateOptions Optional. A RecordCreateOptionsEnum value, that indicates whether an existing file/directory should be opened, or a new file/directory should be created. Default is adFailIfNotExists. This parameter will be ignored if the source parameter is not a URL
Opt ions Optional. One or more RecordOpenOptionsEnum values, that specifies the options for opening the Record. Default is adOpenRecordUnspecified
Username Optional. A user ID that authorizes access to source
Password Optional. A password that verifies the username

Example

Dim rc As New ADODB.Record
Dim rs As ADODB.Recordset
Dim strURL As String
Dim strUsername As String
Dim strPassword As String

strUsername = "xxxxx"
strPassword = "12345"
strURL = "http://www.vbautomation.com/exchange/william/inbox"

rc.Open "", "URL=" & strURL, adModeRead, , adOpenRecordUnspecified, strUsername, strPassword
Set rs = rc.GetChildren

Do Until rs.EOF
Debug.Print rs.Fields("Name") & vbCrLf
rs.MoveNext
Loop

rc.Close
rs.Close
Set rs = Nothing
Set rc = Nothing

There are seven optional parameters.

ConnectModeEnum Constants

Constant

Value

Description

adModeRead 1 Read-only permission
adModeReadWrite 3 Read/write permission
adModeRecursive 0x400000 Sets permissions for children of the Record. Must use with either adModeShareDenyRead or adModeShareDenyWrite. Or must use with adModeShareDenyNone plus any one of adModeRead, adModeReadWrite, or adModeWrite
adModeShareDenyNone 16 Other users can open a connection with all permissions
adModeShareDenyRead 4 No other user can open a connection with read permission
adModeShareDenyWrite 8 No other user can open a connection with write permission
adModeShareExclusive 12 No other user can open a connection
adModeUnknown 0 Default, permission not set or determined
adModeWrite 2 Write-only permissions



RecordCreateOptionsEnum Constants

Constant

Value

Description

adCreateCollection 0x2000 Create a new Record specified by Source parameter
adCreateNonCollection 0 Create a new Record of type adSimpleRecord
adCreateOverwrite 0x4000000 Allows overwrite of existing Record
. You must OR this constant with adCreateCollection, adCreateNonCollection, or adCreateStructDoc
adCreateStructDoc 0x80000000 Create a new Record of type adStructDoc
adFailIfNotExists -1 Default
adOpenIfExists 0x2000000 Provider must open existing Record
. You must OR this constant with adCreateCollection, adCreateNonCollection, or adCreateStructDoc

 
RecordOpenOptionsEnum Constants
 

Constant

Value

Description

adDelayFetchField 0x8000 Retrieve fields associated with Record only when needed
adDelayFetchStream 0x4000 Retrieve stream associated with Record only when needed
adOpenAsync 0x1000 Open in an asynchronous mode
adOpenRecordUnspecified -1 Default, no options selected
adOpenSource 0x800000 Opens source of executable script