Okay, so I'm trying to set the record source of a subform on load event of the main form. I have tried many permutations, some that supposedly work.
main form is called frmBooking, subform is called frm_Location
Here is what I have and I'm still getting errors:
"The expression you entered refers to an object that is closed or doesn't exist"
main form is called frmBooking, subform is called frm_Location
Here is what I have and I'm still getting errors:
"The expression you entered refers to an object that is closed or doesn't exist"
Code:
Private Sub Form_Load()
Dim PartNumber As String
Me!txtPart_Number.SetFocus
PartNumber = Me!txtPart_Number.Text
Dim SQL1 As String
SQL1 = " SELECT Tbl_Location.Location_Category, Tbl_Location.Contract_Number, Tbl_Location.Contract_Details, Tbl_Location.Van_Reg, Tbl_Product.Part_No, Tbl_Current_Location.Date_Loaned, Tbl_User.Details, Tbl_Current_Location.Comments " & _
" FROM Tbl_User INNER JOIN (Tbl_Location INNER JOIN (Tbl_Product INNER JOIN Tbl_Current_Location ON Tbl_Product.ID_Product = Tbl_Current_Location.ID_Product) ON Tbl_Location.ID_Location = Tbl_Current_Location.ID_Location) ON Tbl_User.ID_User = Tbl_Current_Location.ID_User " & _
" WHERE (((Tbl_Current_Location.ID_Product)=[Tbl_Product].[ID_Product]) AND (Tbl_Product.Part_No)=""" & PartNumber & """);"
With Forms![frmBooking]![frm_Location]
.Form.RecordSource = SQL1
.Requery
End With
End Sub