Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
How do I create a recordset based on a range of cells? I assume that a row will constitute a record? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Define what you mean by RecordSet. Are you using ADO, DAO, what?
Is the Excel file open or closed? Where are you doing this from? -- Regards, Tom Ogilvy "Newbie" wrote in message ... Hi, How do I create a recordset based on a range of cells? I assume that a row will constitute a record? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
First you have to reference the DAO or ADO library.
Current best approach is to use ADO 2.7 (if that's still the latest version). Then I think all you can do is loop through the range of cells and append values from selected columns into the recordset. For example: Dim rs As ADODB.Recordset Dim wb As Workbook Dim ws As Worksheet Dim i As Long Set rs = New ADODB.Recordset Set wb = ThisWorkbook Set ws = wb.ActiveSheet rs.Fields.Append "Field1", adBSTR rs.Fields.Append "Field2", adBSTR rs.Open For i = 1 To 50 rs.AddNew rs("Field1").Value = ws.Cells(i, 1).Value rs("Field2").Value = ws.Cells(i, 2).Value rs.Update Next -----Original Message----- Hi, How do I create a recordset based on a range of cells? I assume that a row will constitute a record? . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mike's is an example of a fabricated recordset. I'll point out the
obvious: you can also use ADO to connect to the workbook using the MS OLEBD provider for JET and create an *updateable* recordset based on a SQL SELECT query. -- "Mike" wrote in message ... First you have to reference the DAO or ADO library. Current best approach is to use ADO 2.7 (if that's still the latest version). Then I think all you can do is loop through the range of cells and append values from selected columns into the recordset. For example: Dim rs As ADODB.Recordset Dim wb As Workbook Dim ws As Worksheet Dim i As Long Set rs = New ADODB.Recordset Set wb = ThisWorkbook Set ws = wb.ActiveSheet rs.Fields.Append "Field1", adBSTR rs.Fields.Append "Field2", adBSTR rs.Open For i = 1 To 50 rs.AddNew rs("Field1").Value = ws.Cells(i, 1).Value rs("Field2").Value = ws.Cells(i, 2).Value rs.Update Next -----Original Message----- Hi, How do I create a recordset based on a range of cells? I assume that a row will constitute a record? . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Display a Recordset in Excel | Excel Programming | |||
Excel 2000 - VBA - Stop recordset Data from auto converting | Excel Programming | |||
Excel 2000 VBA recordset manipulation | Excel Programming | |||
Recordset Opening Excel File | Excel Programming | |||
open range (within workbook) as ado recordset - excel vba | Excel Programming |