SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 106 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

DataRegionStart.Activate
Selection.CurrentRegion.Select
Selection.ClearContents
End Sub
Public Sub DoAutoFit()
Me.Worksheet.Select
Me.DataRegionStart.Select
Selection.CurrentRegion.Select
Selection.Columns.AutoFit
Me.InitialCellSelection.Select
End Sub
Listing 2-8. cData Class Code
Option Explicit
Private m_cnn As ADODB.Connection
Private m_rs As ADODB.Recordset
Private m_sConnString As String
Private m_sSQL As String
'
CHAPTER 2 n DATA IN, DATA OUT 93
Public Property Get ConnectString() As String
ConnectString = m_sConnString
End Property
Public Property Let ConnectString(newString As String)
m_sConnString = newString
End Property
Public Property Get SQL() As String
SQL = m_sSQL
End Property
Public Property Let SQL(newSQL As String)
m_sSQL = newSQL
End Property
Function OpenConnection()
If m_sConnString <> "" Then
m_cnn.Open m_sConnString
Else
MsgBox "Cannot open connection", vbOKOnly, "cData: OpenConnection Error"
End If
End Function
Function CloseConnection()
m_cnn.Close
End Function
Function GetData() As ADODB.Recordset
m_rs.Open m_sSQL, m_cnn, adOpenDynamic
Set GetData = m_rs
End Function
Private Sub Class_Initialize()
m_sConnString = ""
m_sSQL = ""
Set m_cnn = New ADODB.Connection
Set m_rs = New ADODB.Recordset
End Sub
Private Sub Class_Terminate()
Set m_cnn = Nothing
Set m_rs = Nothing
End Sub
CHAPTER 2 n DATA IN, DATA OUT 94
Using the cExcelSetup and cData Objects
Now that we??™ve created the objects we need, let??™s put them to use in client code.


Pages:
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118