I get the above error message. I copied your recordset code exactly. I changed the table names and the field names but left the whole thing as it was. But it doesn't even get beyond the second line. It an't find the "Dim rsNew as recordset". I alternated it with the "rsOld" bit but same problem. This is the very first time I've tried using recordsets. Is there sone setting I should have? What am I doing wrong? I tried to add a screenshot here but I don't know how to.
Kevin Robertson
@Reply 7 months ago
You have a missing reference. In the VB Editor go to Tools -- References.
Make sure Microsoft Office 16.0 Object Library is checked.
Sarah BlissOP
@Reply 7 months ago
Thank you Kevin. It wasn't checked and I checked it. I did a compact & repain and closed the database and opened it again but I get the same error.
This is the code but it hasn't even got to the point of starting because of this initial error:
DetailsPrivate Sub AddRecipeCopyBtn_Click()
Dim NewID As Long, ProductID As Long
Dim rsNew As Recordset, rsOld As Recordset
Dim Fld As Field
If IsNull(RecipeID) Then Exit Sub
Me.Refresh
ProductID = ProductNameCombo
' copy the recipe
Set rsOld = CurrentDb.OpenRecordset("SELECT * FROM RecipeT WHERE RecipeID=" & RecipeID)
Set rsNew = CurrentDb.OpenRecordset("RecipeT")
rsNew.AddNew
NewID = rsNew!RecipeID
For Each Fld In rsOld.Fields
If Fld.Name = "RecipeDate" Then
rsNew!RecipeDate = Date
ElseIf Fld.Name = "RecipeNotes" Then
rsNew!RecipeNotes = "(COPY) " & rsOld!RecipeNotes
ElseIf Fld.Name <> "RecipeID" Then
rsNew(Fld.Name) = rsOld(Fld.Name)
End If
Next
rsNew.Update
rsNew.Close
rsOld.Close
Sarah BlissOP
@Reply 7 months ago
I went looking at thoses references and I googled them and found this:
"Microsoft ActiveX Data Objects Recordset 6.0 Library"
I tried it and the error stopped.
I now have another error (LOL) but it's in the SQL bit so it's probably spelling or something.
Let me know if this is something I shouldn't have done - it's way out of my depth here.
And thanks again - and on Sunday too! Thank you!
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access Developer 24.