Hello all,
I have a frmMain with two peer subforms: sfrmSupplements and sfrmProducts.
sfrmProducts shows the "many" records per the "one" current record selected in sfrmSupplement.
In order to establish this relationship, I have the following event code of sfrmSupplements:
The above code works fine and does the trick - except for the first time when the form is opened. Upon opening the form, I get this error message:
The error is captured on this line:
Ignoring the error (or bypassing it with On Error Resume Next) is possible, but then the sfrmProducts records are not bound to the first record of sfrmSupplements that receives the focus upon entry. Moving away to any other record clears the problem and the whole thing works fine.
Any suggestions?
Thank!
Mor
I have a frmMain with two peer subforms: sfrmSupplements and sfrmProducts.
sfrmProducts shows the "many" records per the "one" current record selected in sfrmSupplement.
In order to establish this relationship, I have the following event code of sfrmSupplements:
Code:
Private Sub Form_Current()
On Error GoTo Form_Current_Error
Dim strSql As String
strSql = "SELECT tblProducts.Product_Code, tblProducts.Supplement_Code, tblProducts.Units_Code, tblProducts.Number_of_Units, tblProducts.Bottles_in_Stock, tblProducts.Stock_Date, tblProducts.Product_Price, tblProducts.Comments_Medium FROM tblProducts WHERE tblProducts.Supplement_Code = '" & Me.Supplement_Code & "'"
Me.Parent.Form!sfrmProductsInSupplements.Form.RecordSource = strSql
Me.Parent.Form!sfrmProductsInSupplements.Form.Requery
Form_Current_Exit:
Exit Sub
Form_Current_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Current of VBA Document Form_sfrmFoodSupplements"
Resume Form_Current_Exit
Resume
End Sub
The above code works fine and does the trick - except for the first time when the form is opened. Upon opening the form, I get this error message:
Runtime error 2455:
You entered an expression that has an invalid reference to the property Form/Report.
The error is captured on this line:
Code:
Me.Parent.Form!sfrmProductsInSupplements.Form.RecordSource = strSql
Ignoring the error (or bypassing it with On Error Resume Next) is possible, but then the sfrmProducts records are not bound to the first record of sfrmSupplements that receives the focus upon entry. Moving away to any other record clears the problem and the whole thing works fine.
Any suggestions?
Thank!
Mor