G
Guest
Thanks for taking the time to read my question.
I am trying to write to a table with code, but when I get to .edit, I get an
error telling me "No Current Record", and I don't know why.
Any ideas?
Brad
Public Sub TransferData()
Dim dbs As Database, rst As Recordset, qdf As QueryDef, rst2 As Recordset
Dim x As Integer
Dim CurrentPyramid As String
Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset("Table1")
Set rst2 = CurrentDb.OpenRecordset("tblPyramidPlanner")
rst.MoveFirst
x = 1
Do Until rst.EOF
CurrentPyramid = rst!SowBarn
With rst2
.AddNew
!SowBarn = rst!SowBarn
.Update
End With
Do Until CurrentPyramid <> rst!SowBarn Or IsNull(rst!SowBarn)
With rst2
.Edit
!Forms("Barn" & x) = rst!FeederBarn
.Update
x = x + 1
End With
rst.MoveNext
Loop
Loop
qdf.Close
rst.Close
rst2.Close
Set qdf = Nothing
Set rst = Nothing
Set rst2 = Nothing
Set dbs = Nothing
End Sub
I am trying to write to a table with code, but when I get to .edit, I get an
error telling me "No Current Record", and I don't know why.
Any ideas?
Brad
Public Sub TransferData()
Dim dbs As Database, rst As Recordset, qdf As QueryDef, rst2 As Recordset
Dim x As Integer
Dim CurrentPyramid As String
Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset("Table1")
Set rst2 = CurrentDb.OpenRecordset("tblPyramidPlanner")
rst.MoveFirst
x = 1
Do Until rst.EOF
CurrentPyramid = rst!SowBarn
With rst2
.AddNew
!SowBarn = rst!SowBarn
.Update
End With
Do Until CurrentPyramid <> rst!SowBarn Or IsNull(rst!SowBarn)
With rst2
.Edit
!Forms("Barn" & x) = rst!FeederBarn
.Update
x = x + 1
End With
rst.MoveNext
Loop
Loop
qdf.Close
rst.Close
rst2.Close
Set qdf = Nothing
Set rst = Nothing
Set rst2 = Nothing
Set dbs = Nothing
End Sub