Update .accdb file from within Word vba
I wrote, and have been using, Word VBA for some time with an early version of Access (.mdb suffix), and all works fine. I want to change it to use the current Access .accdb suffix. I've tried just changing the suufix from .mdb to .accdb but that gives an error "User defined type not defined" when it tries to execute "dbs As DAO.database".
Any help will be very much appreciated as I'm now out of my depth! Relevant scraps of code are shown below.
Option Explicit
Dim MasterDbDrive As String
Private Sub UserForm_Initialize()
MultiMaxCount = 10 ' maximum prints that can be held before printing
'NetworkReply = 0
MasterDbDrive = "C:" ' set to C: for testing on a local PC
RootFolder = MasterDbDrive + "\Helpline Docs\Standard Letters\"
MasterFolder = RootFolder & "Master copies\" 'path of master documents
PrevFolder = RootFolder & "Previous versions\" 'to save previous letter
MasterDb = MasterFolder & "Standard Letters.mdb"
FFUI_Start:
On Error GoTo FFUIerr1
ChDrive MasterDbDrive
GoTo FFUIerr1x
-----------------------------------------------------------------------------------------------------
Private Sub WriteToDB()
Dim dbs As DAO.database
Dim rst As DAO.recordset
Set dbs = OpenDatabase(Name:=MasterDb)
Set rst = dbs.OpenRecordset(DbTable, dbOpenTable)
With rst
.AddNew
.Fields("Addressee") = FrmMainB.Addressee
.Fields("Position") = FrmMainB.Position
.Fields("Organisation") = FrmMainB.Organisation
.Fields("Address1") = FrmMainB.Address1
.Fields("Address2") = FrmMainB.Address2
.Fields("Address3") = FrmMainB.Address3
.Fields("Address4") = FrmMainB.Address4
.Fields("PostCode") = FrmMainB.PostCode
.Fields("Salutation") = FrmMainB.Salutation
.Update
End With
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
End Sub
|