Oops, I spoke too soon.
Running that as a query runs properly, but running the same query from VBA gives me a run-time error 3314 "You must enter a value in 'tblPartsList.Partnum' field.
Any ideas?
Here's the vba that I'm running... it errors on the line " db.Execute strSqlNew, dbFailOnError"
Code:
Private Sub PriceUpdate()
Dim db As DAO.Database
Dim strSqlNew As String
Dim strSqlDisc As String
Dim strSqlUpdate As String
strSqlNew = "UPDATE tblPartsList RIGHT JOIN tblAll ON tblPartsList.Partnum=tblAll.PartNum " _
& "SET tblPartsList.Partnum = tblAll.Partnum, tblPartsList.Price = tblAll.Price, " _
& "tblPartsList.Vendor = tblAll.Vendor WHERE tblPartslist.Partnum IS NULL;"
strSqlDisc = "UPDATE tblPartsList LEFT JOIN tblAll ON tblPartsList.Partnum=tblAll.PartNum " _
& "SET tblPartsList.Legacy = True WHERE tblAll.Partnum IS NULL;"
strSqlUpdate = "UPDATE tblPartsList INNER JOIN tblAll ON tblPartsList.Partnum=tblAll.PartNum SET tblPartsList.Price = tblAll.Price;"
Set db = DBEngine(0)(0)
db.Execute strSqlNew, dbFailOnError
db.Execute strSqlDisc, dbFailOnError
db.Execute strSqlUpdate, dbFailOnError
End Sub
Upon further thought, I think the issue is that the excel file has records with no part number, which I don't want to import, but the access tbl has data validation set to require a part number and not allow 0 length fields.
How do I catch that error and ignore it?