Thread: Excel to Access
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Excel to Access

Thanks! I ended up using changing the Data Type in all of the Access fields
to Text. Text can accommodate up to 255 characters, and it seemed to be very
flexible (in terms of what data types can flow into all the fields) too.

Thanks again,
Ryan--

--
RyGuy


"roger" wrote:

"RyGuy" wrote in message
...
I run the code below and get an error 'Data Type Conversion Error':

Sub DAOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
Set db = OpenDatabase("C:\TFI.mdb")
' open the database
Set rs = db.OpenRecordset("tblTFI", dbOpenTable)
' get all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("ID") = Range("A" & r).Value


What datatype is tblTFI.ID, and what sort of data is in Range("A" & r)?

Does this work?

..Fields("ID") = clng(Range("A" & r).Value)

What do
I need to do to overwrite all data in the Access table with the current

data
from the Excel sheet?


Try -
db.Execute "delete * from tblTFI", dbFailOnError


--
roger