I'm trying to display all of the results of a query in a textbox on my form. The form that this query is happening on is based on a different table than the data that I'm displaying, so I think I need to run a SQL query.
The previous maintainer of this DB used the following SQL string to make the query:
Code:
Source = "SELECT DATE_ENTERED, USER_ID, COMMENT_STR FROM LOT_COMMENTS WHERE LOT_NUMBER = '" & LOT_NUMBER & "' ORDER BY DATE_ENTERED DESC;"
The table that is being queried, LOT_COMMENTS, is organized like this:
Code:
Table LOT_COMMENTS =
record_id | LOT_NUMBER | USER_ID | LOT_COMMENTS | DATE_ENTERED
550 | 66666666 | 109 | First Comment | 12/14/2019
551 | 66666666 | 210 | Second Comment| 12/14/2019
552 | 66666666 | 311 | Third Comment | 12/14/2019
and the results are something like:
Code:
12/14/2019 109 First Comment
12/14/2019 210 Second comment
12/14/2019 311 Third comment
I have tried putting the SQL string into a function:
Code:
function getComments()
dim Source as string
Source = "SELECT DATE_ENTERED, USER_ID, COMMENT_STR FROM LOT_COMMENTS WHERE LOT_NUMBER = '" & LOT_NUMBER & "' ORDER BY DATE_ENTERED DESC;"Source = "SELECT DATE_ENTERED, USER_ID, COMMENT_STR FROM LOT_COMMENTS WHERE LOT_NUMBER = '" & LOT_NUMBER & "' ORDER BY DATE_ENTERED DESC;"
getComments = Source
end function
but VBA doesn't like this, when I use the function as the data source(ie, Control Source =getComments() ), I get the full SQL string in the comments instead of the desired return value.
What am I missing?