V
Varne
Hi!
I have restricted Internet access so please forgive if I reply late.
I am on Access 2007 Northwind. I got these codes from Microsoft Help Chapter
1 ADO example but they do not work. Every Macro seems to have undefined
variables. I have shown below the macro GetData. First variable not efined
is ‘grdDisplay1’ in the last line before the error handler. I have added MS
ADO 2008 to the object library.
Could some help?
Thanks.
Option Explicit
Dim m_oRecordset As ADODB.Recordset
Dim m_sConnStr As String
Dim m_flgPriceUpdated As Boolean
Private Sub GetData()
On Error GoTo GetDataError
Dim sSQL As String
Dim oConnection1 As ADODB.Connection
m_sConnStr = "Provider='SQLOLEDB';Data Source='MySqlServer';" & _
"Initial Catalog='Northwind';Integrated Security='SSPI';"
' Create and Open the Connection object.
Set oConnection1 = New ADODB.Connection
oConnection1.CursorLocation = adUseClient
oConnection1.Open m_sConnStr
sSQL = "SELECT ProductID, ProductName, CategoryID, UnitPrice " & _
"FROM Products"
' Create and Open the Recordset object.
Set m_oRecordset = New ADODB.Recordset
m_oRecordset.Open sSQL, oConnection1, adOpenStatic, _
adLockBatchOptimistic, adCmdText
m_oRecordset.MarshalOptions = adMarshalModifiedOnly
' Disconnect the Recordset.
Set m_oRecordset.ActiveConnection = Nothing
oConnection1.Close
Set oConnection1 = Nothing
' Bind Recordset to the DataGrid for display.
Set grdDisplay1.DataSource = m_oRecordset
Exit Sub
GetDataError:
If Err <> 0 Then
If oConnection1 Is Nothing Then
HandleErrs "GetData", m_oRecordset.ActiveConnection
Else
HandleErrs "GetData", oConnection1
End If
End If
If Not oConnection1 Is Nothing Then
If oConnection1.State = adStateOpen Then oConnection1.Close
Set oConnection1 = Nothing
End If
End Sub
I have restricted Internet access so please forgive if I reply late.
I am on Access 2007 Northwind. I got these codes from Microsoft Help Chapter
1 ADO example but they do not work. Every Macro seems to have undefined
variables. I have shown below the macro GetData. First variable not efined
is ‘grdDisplay1’ in the last line before the error handler. I have added MS
ADO 2008 to the object library.
Could some help?
Thanks.
Option Explicit
Dim m_oRecordset As ADODB.Recordset
Dim m_sConnStr As String
Dim m_flgPriceUpdated As Boolean
Private Sub GetData()
On Error GoTo GetDataError
Dim sSQL As String
Dim oConnection1 As ADODB.Connection
m_sConnStr = "Provider='SQLOLEDB';Data Source='MySqlServer';" & _
"Initial Catalog='Northwind';Integrated Security='SSPI';"
' Create and Open the Connection object.
Set oConnection1 = New ADODB.Connection
oConnection1.CursorLocation = adUseClient
oConnection1.Open m_sConnStr
sSQL = "SELECT ProductID, ProductName, CategoryID, UnitPrice " & _
"FROM Products"
' Create and Open the Recordset object.
Set m_oRecordset = New ADODB.Recordset
m_oRecordset.Open sSQL, oConnection1, adOpenStatic, _
adLockBatchOptimistic, adCmdText
m_oRecordset.MarshalOptions = adMarshalModifiedOnly
' Disconnect the Recordset.
Set m_oRecordset.ActiveConnection = Nothing
oConnection1.Close
Set oConnection1 = Nothing
' Bind Recordset to the DataGrid for display.
Set grdDisplay1.DataSource = m_oRecordset
Exit Sub
GetDataError:
If Err <> 0 Then
If oConnection1 Is Nothing Then
HandleErrs "GetData", m_oRecordset.ActiveConnection
Else
HandleErrs "GetData", oConnection1
End If
End If
If Not oConnection1 Is Nothing Then
If oConnection1.State = adStateOpen Then oConnection1.Close
Set oConnection1 = Nothing
End If
End Sub