I'm trying to generate a recordset and use it to populate a subform.
My SQL is good because I have run it in the Access query builder and it returns the expected result I just can't get anything to appear in the subform!
I used a loop to fill the subform but nothing is showing. If anyone could point out the idiot mistake that would be great!
Code below:
My SQL is good because I have run it in the Access query builder and it returns the expected result I just can't get anything to appear in the subform!
I used a loop to fill the subform but nothing is showing. If anyone could point out the idiot mistake that would be great!
Code below:
Code:
Private Sub txtPart_Number_AfterUpdate()
Dim SQL1 As String
Dim PartNumber As String
PartNumber = Me!txtPart_Number.Text
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim rs1 As New ADODB.Recordset
rs1.ActiveConnection = cnn1
rs1.CursorType = adOpenDynamic
rs1.LockType = adLockOptimistic
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 & """);"
rs1.Open SQL1
With rs1
'Ensure recordset is populated
If Not .BOF And Not .EOF Then
'not necessary but good practice
.MoveLast
.MoveFirst
While (Not .EOF)
Me!frmLocation.Form!txtLocation_Category.RecordSource = "Location_Category"
Me!frmLocation.Form!txtContract_Number.RecordSource = "Contract_Number"
Me!frmLocation.Form!txtContract_Details.RecordSource = "Contract_Details"
Me!frmLocation.Form!txtVan_Reg.RecordSource = "Van_Reg"
Me!frmLocation.Form!txtPart_No.RecordSource = "Part_No"
Me!frmLocation.Form!txtDate_Loaned.RecordSource = "Date_Loaned"
Me!frmLocation.Form!txtDetails.RecordSource = "Details"
Me!frmLocation.Form!txtComments.RecordSource = "Comments"
Me!frmLocation.Form!txtComments.Requery
.MoveNext
Wend
End If
End With
' Debug.Print PartNumber
rs1.Close
cnn1.Close
Set rs1 = Nothing
Set cnn1 = Nothing
End Sub