I have a subform called subfrm_Sites which is a child of a form called frm_ContractorsAndSites. subfrm_Sites is a datasheet view.
In subfrm_Sites I have the following code which populates some of the fields just before a new row is inserted. Now this code works perfectly when the subform is open directly (i.e. isn't a child of any form) but fails with a 'Runtime error 2450: Cannot find the form 'subfrm_Sites'.
Now I have tried a number of permutations of referring to the controls on the subform, none of which have worked. I'm guessing there's a simple solution to this I'm just missing something obvious.
Could anyone help me out here and let me know where I'm going wrong?
Help muchly appreciated,
John
In subfrm_Sites I have the following code which populates some of the fields just before a new row is inserted. Now this code works perfectly when the subform is open directly (i.e. isn't a child of any form) but fails with a 'Runtime error 2450: Cannot find the form 'subfrm_Sites'.
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Dim SQL As String
SQL = "SELECT MS_SysCode, MS_Cost FROM tbl_Materials"
Set rs = db.OpenRecordset(SQL)
While Not rs.EOF ' Loop trough the table
[Forms]![subfrm_Sites].Controls(rs("MS_SysCode")) = rs("MS_Cost")
rs.MoveNext
Wend
rs.Close
db.Close
End Sub
Now I have tried a number of permutations of referring to the controls on the subform, none of which have worked. I'm guessing there's a simple solution to this I'm just missing something obvious.
Could anyone help me out here and let me know where I'm going wrong?
Help muchly appreciated,
John