Problem in Access VBA Help

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
 
J

June7 via AccessMonster.com

The grd of grdDisplay1 infers this is a gridview object. I have not used
them but believe they are an object placed on a form just like a listbox
would be. But think they are VB6 and VB.Net objects, not Access. Will have
come up with alternate code for whatever this is supposed to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top