PDA

View Full Version : Updating records and getting Runtime Error 3075


reidi_lexi
Nov 3, 2010, 04:44 AM
Hello there!
For the access program I am going to do, there is already an existing data. I had imported it from Excel. Now, I have created a URN field from the look up table and wanted to update it to the main table which comprises the existing data. I've used the following code but I keep on getting the Runtime Error 3075 message. Here is my code:

Private Sub Command0_Click()
Dim md As Recordset
Dim phr As Recordset
Dim entry As Recordset
Dim phrname As String
Dim mdname As String

Set md = CurrentDb.OpenRecordset("tblMDinfo")
Set phr = CurrentDb.OpenRecordset("tblPHRinfo")
Set entry = CurrentDb.OpenRecordset("tblEntryTrack")
phrname = phr("fldPHR")
mdname = md("fldMDName")

Do While entry.EOF = False
CurrentDb.Execute "update tblEntryTrack set [tblEntryTrack].[fldPHRID] = [tblPHRinfo].[fldPHRID] where [tblEntryTrack].[fldPHR] = " & phrname & ";"
CurrentDb.Execute "update tblEntryTrack set [tblEntryTrack].[fldMDID] = [tblMDinfo].[fldMDID] where [tblEntryTrack].[fldMDName] = " & mdname & ";"
Loop
MsgBox "done!"
End Sub

Help anyone?

ScottGem
Nov 3, 2010, 07:37 AM
First what is the full and Exact message you are getting. Second, What data types are fldPHR and fldMDName? Also what info is in them? Define URN field?

And why do this in code? Why not just run an Update query?

If I follow what you are doing, you added a Foreign key field to replace name as the FK, which is a good idea. But then all you need is to create an Update query, joined on the old FK and run it. No need for the looping code which has syntax errors.

reidi_lexi
Nov 3, 2010, 10:01 PM
That did give me an idea... It's okay now. Thanks!!

ScottGem
Nov 4, 2010, 03:39 AM
That did give me an idea...It's okay now. Thanks!!!

Glad to help, how did you solve it?