GulfImages
Technical User
Hello All,
I have this bit of code that was derived from a lot of help here (Thanks AceMan1) and it works great on a main form but for some reason when I try to run it from a button on a main form, for data in a subform I get a Compile Error: Expected Function or Variable. When I compile the code I get no error, only when I try to run it.
I don't know if it's a syntax thing with the subform or what. Any help is greatly appreciated.
I have this bit of code that was derived from a lot of help here (Thanks AceMan1) and it works great on a main form but for some reason when I try to run it from a button on a main form, for data in a subform I get a Compile Error: Expected Function or Variable. When I compile the code I get no error, only when I try to run it.
I don't know if it's a syntax thing with the subform or what. Any help is greatly appreciated.
Code:
Sub AddNewRecords()
Dim db As DAO.Database, rst As DAO.Recordset, ctl As Control
Dim myform As Form
Set myform = Forms!frmInvoices!ItemsSub.Form
Set db = CurrentDb
Set rst = db.OpenRecordset("tblInvoicesItems", DB_OPEN_TABLE)
rst.AddNew
For Each ctl In myform.Controls
If ctl.Tag = "D" Then rst(ctl.Name) = ctl
Next
rst.Update
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub