Excel to Access - TechRepublic
General discussion
July 6, 2003 at 06:52 PM
dennishanson

Excel to Access

by dennishanson . Updated 23 years ago

I am currently trying to programe an Excel spreadsheet to transfer info to an existing Access Data Base using the following VB code:-

Sub Add_Record_to_Contacts()

‘ Add_Record_to_Contacts Macro
‘ Macro recorded 04/07/2003 by Dennis R. Hanson

Dim DBS As Database
Dim RecSet As Recordset
Dim DBox As DialogSheet

‘ Open the database
dbname = “C:\Private\Contacts.mdb”
Set DBS = OpenDatabase(dbname)

Set RecSet = DBS.OpenRecordset(Name:=”CV-Engineering”, Type:=dbOpenDynaset)

With RecSet
.AddNew

.fields(“Surname”).Value = Sheets(“CV-Info”).Range(“B1”).Value
.fields(“Middle Name”).Value = Sheets(“CV-Info”).Range(“B2”).Value
.fields(“Forname”).Value = Sheets(“CV-Info”).Range(“B3”).Value.Update

End With

‘Close the Data Base
DBS.Close

End Sub

When I run the code I get an “Compile Error” meassage tell me “User-Defined Type not Defined”

Any help please.

Dennis

This discussion is locked

All Comments