ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA Excell/access prob (https://www.excelbanter.com/excel-discussion-misc-queries/222249-vba-excell-access-prob.html)

[email protected]

VBA Excell/access prob
 
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




All times are GMT +1. The time now is 08:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com