View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
gab1972 gab1972 is offline
external usenet poster
 
Posts: 57
Default Copy an Access recordset starting with Column 2

On Jul 19, 10:39*pm, Joel wrote:
YOU have to change your SQL statement. *The SQL has two parts that you need
to look at.

1) The Select portion which defines which records to retrieve. which defines
the table to use and the filters which is specified by the Where statements.
2) The Orderby which specifies which fields to retrieve and the order to
place the fields into the excel table.



"gab1972" wrote:
I am bringing information from an Access recordset into Excel. *I want
to
start copying the recordset data starting with column two in the
Access
record. *Column one is my primary key identifier and I don't want
that.
I'm thinking it has something to do with .Fields???


Below is my coding so far...


'Copy the matched recordset into the worksheet starting at column
"AN"
With wsSheet1
..Cells(2, 40).CopyFromRecordset rs2.Fields(2,?????) *<----unsure here
End With
'Close connections with permit_life
rs2.Close


Any help would be greatly appreciated.


So you're saying I need to change something in these lines of coding?

' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=Z:\COMMON FILES\Encroachment Permits
\Permit.Tracker\Database\Permit.Tracker.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
str = "SELECT * FROM permit_info WHERE permit_num = '" & strPnum &
"'"
rs.Open str, cn, adOpenKeyset, adLockOptimistic

permit_info is the name of the database. strPnum is a number stored
from a userform drop down menu. I have several databases and I use
the strPnum value as the primary key in each one. I want Excel to
pull the information from the recordset, but I want it to start at the
second column, not the first, because I don't need the permit number
column brought over.

Thanks again