I want to fill a data grid without using and ADO control so it is not bound and left open all the time.
I found this in help and thought I could modify it to read in Access data but can't get it to work.
If I 'REM' out the Goto Skip it fills the data grid with two fields, ID and name
other wise it’s all blank
It does read in my data ‘casue I can print it in the Debug window
Debug.pring rsNames!
Help
Boss wants me to use a List box. I want to prove a Data grid is superior.
DougP, MCP, A+
I found this in help and thought I could modify it to read in Access data but can't get it to work.
Code:
Private WithEvents Conn2 As ADODB.Connection
Private WithEvents rsNames As ADODB.Recordset
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
Set Data = rsNames
End Sub
Private Sub Class_Initialize()
' Add the names of the new datamember to the DataMember collection
' This allows other objects to see the available DataMembers
DataMembers.Add "BusinessOps"
Dim SQLCode As String
Set Conn2 = New ADODB.Connection
Conn2.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\main.mdb"
Set rsNames = New ADODB.Recordset ' Set the object variable.
SQLCode = "SELECT * FROM [BusinessOps];"
rsNames.Open SQLCode, Conn2, adOpenStatic, adLockOptimistic
' Create a recordset with two fields and open the recordset. The
' first record has an integer data type and the second is a string,
' with a maximum of 256 characters. The CursorType is set to
' OpenStatic--an updatable snapshot of a set of records. The
' LockType is set to LockOptimistic to allow updates to the
' recordset
GoTo Skip
With rsNames
.Fields.Append "ID", adInteger
.Fields.Append "Name", adBSTR, 255
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open
End With
Dim i As Integer
For i = 1 To 10 ' Add ten records.
rsNames.AddNew
rsNames!ID = i
rsNames!Name = "Name " & i
rsNames.Update
Next i
Skip:
rsNames.MoveLast
rsNames.MoveFirst ' Move to the beginning of the recordset.
End Sub
If I 'REM' out the Goto Skip it fills the data grid with two fields, ID and name
other wise it’s all blank
It does read in my data ‘casue I can print it in the Debug window
Debug.pring rsNames!
Help
Boss wants me to use a List box. I want to prove a Data grid is superior.
DougP, MCP, A+