Hi
I had nearly exhausted all ways of connecting an ado recordset to an Excel 97 workbook for data processing. I then finally had success setting up a local PC ODBC Data Source. The ado recordset populates the ado recordset correctly and the Data Grid linked to the ado datasource displays the underlying Excel Row/col data including Column headers correctly. However, it is not possible to modify data in the data grid cells. They appear 'locked' despite all the properties set for the Data Grid being set appropriately; AllowAddnew, AllowUpdate, Allowdelete all set to 'True'.
I have set the ado connection string to include 'readOnly = False' and used an 'adOpenkeyset' argument thinking it was a data connection problem. Is this an issue with the ODBC Data Source I have set up - but limited connection options with this object anyway, or something else. I am trying to avoid other Data Source connections because I have tried most using KB articles and associated threads in Tek-Tips and all my attempts report errors when the data linking is executed.
Many thanks in anticipation of your help.
PS Processing part of code in its 'infancy' below!
I had nearly exhausted all ways of connecting an ado recordset to an Excel 97 workbook for data processing. I then finally had success setting up a local PC ODBC Data Source. The ado recordset populates the ado recordset correctly and the Data Grid linked to the ado datasource displays the underlying Excel Row/col data including Column headers correctly. However, it is not possible to modify data in the data grid cells. They appear 'locked' despite all the properties set for the Data Grid being set appropriately; AllowAddnew, AllowUpdate, Allowdelete all set to 'True'.
I have set the ado connection string to include 'readOnly = False' and used an 'adOpenkeyset' argument thinking it was a data connection problem. Is this an issue with the ODBC Data Source I have set up - but limited connection options with this object anyway, or something else. I am trying to avoid other Data Source connections because I have tried most using KB articles and associated threads in Tek-Tips and all my attempts report errors when the data linking is executed.
Many thanks in anticipation of your help.
PS Processing part of code in its 'infancy' below!
Code:
Private Sub cmdExcelDataLink_Click()
Dim connString As String
Dim oconn As ADODB.Connection
Dim ors As ADODB.Recordset
Dim nCols As Integer
Dim strSQL As String
Dim strTableName As String
Dim strTemp As String
Dim intRecordCount As Integer
Dim J As Integer
'Note Read Only attriute must be set to false with ODBC - True by default
connString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=KumonExcel; ReadOnly = false;"
' this assumes that the first row contains headers
strTableName = "[Kumon$]"
strSQL = "SELECT * FROM " & strTableName
'strSQL = strSQL & Where
Set ors = New ADODB.Recordset
ors.Open strSQL, connString, adOpenKeyset, adLockOptimistic
nCols = ors.Fields.Count
Set DataGrid1.DataSource = ors.DataSource
DataGrid1.Refresh
With ors
.MoveLast
.MoveFirst
intRecordCount = .RecordCount
.MoveFirst
MsgBox "No of Records: " & intRecordCount
For J = 1 To intRecordCount - 1
If IsNull(.Fields(0).Value) = True Then
Exit Sub
'If no field data Exit. recordcount may contain data in other
'workbook columns below record count
Else
strTemp = .Fields(0).Value
MsgBox strTemp
End If
.MoveNext
Next
End With
End Sub