LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default Import into Access from Excel, passing a variable for the field...

Hello all,

I have an Excel spreadsheet with a header that contains the exact
same
30 names as the corresponding 30 fields in an Access DB table, and
Row
2 below the Header contains the data I want to import. Instead, of
physically typing all 30 fields in the code, I have a macro that
loops
through each "field" name that it got from the spreadsheet header.
When I run this macro I get "run-time error '3265' Item not found in
this collection', however, when I specify the actual field Name
manually it works. This what I have:


Dim iColumn As Integer
Dim FieldName As String
Dim FieldData As String


Dim AccessDB As Database
Dim AccessRecordSet As Recordset


Set AccessDB = OpenDatabase("C:\MyDataBase.mdb")
Set AccessRecordSet = AccessDB.OpenRecordset("MyTable",
dbOpenDynaset)


With AccessRecordSet
.AddNew
For iColumn = 1 To 30
FieldName = Cells(1, iColumn).Value
FieldData = Cells(2, iColumn).Value
![FieldName] = FieldData
Next iColumn
.Update
End With


Again, if change: ![FieldName] = FieldData to, let's say: !
[Customer] = FieldData , then it works fine (but then it would only
import into the database on that particular field 30 times).


Do I need to reset my FieldName variable to something other than
String? I've tried even rewriting the code to the following but that
didn't work either:


![ & "FieldName" & ] = FieldData

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing string as array variable (Pivot VBA) klingongardener Excel Discussion (Misc queries) 2 December 23rd 06 07:58 PM
import excel to Access has a problem with text field ABCBAC Excel Worksheet Functions 0 November 11th 06 08:09 AM
Passing Variable Number of Arguments to a Sub blatham Excel Discussion (Misc queries) 4 December 10th 05 10:36 AM
Passing Variable to LINEST RW Excel Worksheet Functions 5 May 24th 05 07:00 PM
Import from Database using field from excel. BD Excel Discussion (Misc queries) 1 May 10th 05 10:31 PM


All times are GMT +1. The time now is 06:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"