angusdcrouse
New member
- Local time
- Today, 00:25
- Joined
- Dec 10, 2020
- Messages
- 2
Hello all,
I'm facing an issue that results in my SELECT query not returning all the results I am expecting. This could be due to an issue with my query or tables but I think it's most likely due to my usage of VBA in populating one of my tables hence why I am posting in the VBA section.
In a very simple case have 2 tables:
When I populate the [productSearch] table manually and refresh my query all expected results are returned - all very basic and no problems so far.
I then have a very simple form with a multi line text box and the intention is for the user to use this and enter multiple products to search for on separate lines. There is a button below this text box and the related sub reads clears out any old data from the [productSearch] table and inserts new records for each line of the text box.
Whilst the sub is successfully populating my [productSearch] table with records for every line of the text box, when I then run my query only the last record from my [productSearch] table is showing in the results even though all other records appear to be valid matches.
If I manually edit one of the problematic records in [productSearch] to a different value and then edit it back to the correct string the query will then correctly show the record so it appears to be an issue with Private Sub ButtonSearch_Click() and how it is populating the [productSearch] table but I'm not really sure why.
I've tried to search for the issue but unfortunately all the results I find are for people asking how to return only the last record which is obviously what I'm trying to avoid.
Thanks
I'm facing an issue that results in my SELECT query not returning all the results I am expecting. This could be due to an issue with my query or tables but I think it's most likely due to my usage of VBA in populating one of my tables hence why I am posting in the VBA section.
In a very simple case have 2 tables:
- [product] - containing all products with fields for productName and productNumber.
- [productSearch] - which contains a list of all productNames the user wants to search for
Code:
SELECT product.*
FROM productSearch
INNER JOIN product ON productSearch.productSearchName = product.productName;
When I populate the [productSearch] table manually and refresh my query all expected results are returned - all very basic and no problems so far.
I then have a very simple form with a multi line text box and the intention is for the user to use this and enter multiple products to search for on separate lines. There is a button below this text box and the related sub reads clears out any old data from the [productSearch] table and inserts new records for each line of the text box.
Code:
Private Sub ButtonSearch_Click()
Dim lines: lines = Split(Me.TextSearchList, vbLf)
DoCmd.SetWarnings False
On Error Resume Next
DoCmd.RunSQL "DELETE * FROM productSearch"
On Error GoTo 0
Dim i As Long
For i = 0 To UBound(lines)
'MsgBox lines(i)
DoCmd.RunSQL "INSERT INTO productSearch(productSearchName) VALUES ('" & lines(i) & "');"
Next
DoCmd.SetWarnings True
End Sub
Whilst the sub is successfully populating my [productSearch] table with records for every line of the text box, when I then run my query only the last record from my [productSearch] table is showing in the results even though all other records appear to be valid matches.
If I manually edit one of the problematic records in [productSearch] to a different value and then edit it back to the correct string the query will then correctly show the record so it appears to be an issue with Private Sub ButtonSearch_Click() and how it is populating the [productSearch] table but I'm not really sure why.
I've tried to search for the issue but unfortunately all the results I find are for people asking how to return only the last record which is obviously what I'm trying to avoid.
Thanks