Update table using data in a different .mdb

R

Rick

I'm trying to update fields in a table in a mdb using fields in a
table from another mdb.

I'm using a VBA module in Access 2003.

I keep getting the same error "Patients not found" at the RunSQL
statement.

Any pointers would be welcome. thanks, rick.

Sub merge()

Rem update address fields in patients table in A.mdb using table(s) in
Update.mdb

Rem 51 tables in A.mdb Patients ...
Rem 3 tables in update.mdb April2011 July2011 Dec2011

Rem use DAO for .mdb files
Rem use ADO for SQL (mysql or sql server)

' update database (this module is stored in update.mdb)
Dim mail As DAO.Database
Set mail = CurrentDb
Rem DoCmd.OpenTable ("April2011") ' causes a window to open that
displays the data - don't need this to display?
Dim newdata As Recordset
Set newdata = mail.OpenRecordset("April2011")
MsgBox newdata.Name ' confirm table exists
DoCmd.RunSQL ("select * from April2011;")

' primary database
Dim ws As DAO.Workspace
Set ws = DBEngine(0)
Dim fwp As DAO.Database
Set fwp = ws.OpenDatabase("M:A.mdb")
Dim Patients As Recordset
Set Patients = fwp.OpenRecordset("Patients")
Rem DoCmd.OpenTable ("Patients") ' fails because fwp is not the
Current db
MsgBox Patients.Name

Dim l1, l2, l3, l4, strSQL As String

l1 = "UPDATE Patients "
l2 = "INNER JOIN April2011 ON Patients.id = April2011.id "
l3 = "SET Patients.addressline1 = April2011.addressline1 ,"
l4 = " Patients.addressline2 = April2011.addressline2 ;"

strSQL = l1 & l2 & l3 & l4

DoCmd.RunSQL strSQL ' fails cant find Patients

MsgBox "DONE"

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