Examples: CreateADOConnection method

The following example creates an ADO connection and issues a command to retrieve all of the customer records from the RM00101 table in the current company’s database. Note how the IntercompanyID property of the UserInfo object is used to set the default database for the ADO connection.

Private Sub CreateADOConnection_Click()
	Dim cn As New ADODB.Connection
	Dim rst As New ADODB.Recordset
	Dim cmd As New ADODB.Command

	On Error Resume Next

	'Retrieve an ADO connection for the current user
	Set cn = UserInfoGet.CreateADOConnection()

	'Set the connection properties
	cn.CursorLocation = adUseClient

	'Set the current database, using the IntercompanyID property
	cn.DefaultDatabase = UserInfoGet.IntercompanyID

	'Create a command to select all customers
	cmd.ActiveConnection = cn
	cmd.CommandType = adCmdText
	cmd.CommandText = "Select * from RM00101"
	Set rst = cmd.Execute

	'Display the number of rows retrieved
	MsgBox rst.RecordCount

	'Close the connection
End Sub

Documentation Feedback