VBA Excell/access prob

B

benjamin.fisk

Here is the problem I am using a Rube Goldberg device to get two
programs to work with each other the first is a database which exports
records from its proprietary database format to excel. So I have taken
all of these excel files and consolidated them using code that I have
written now here is the problem I am trying to get the code to import
the serial # and the class name into the access database. But when I
do I get a 3421 data mismatch error. This is because the class field
is actually a lookup field with a primary key that is a number and a
description that is a memo I am trying. The lookup needs to be a text
input but it logs by class number

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:\Documents and Settings\fiskb001\Desktop
\2009.mdb")
' open the database
Set rs = db.OpenRecordset("main table", dbOpenTable)
' get all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) <> ""
' repeat until first empty cell in column A
With rs
.AddNew ' create a new recor
.Fields("Serial #") = Range("B" & r).Value
.Fields("class") = Range("C" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top