I'm trying to run an SQL Query in VBA to populate a combobox. I'd like the combobox to display all Start Times ([Schedule Data].[ApptStart]) on a given date, chosen from a date picker ([ApptDate] on the form.) I've tried various iterations of the statement below but can't seem to get anything but errors and a blank combo box.
Me.ComboTimeList.RowSource =
"SELECT [Schedule Data].[ApptStart]
FROM [Schedule Data]
WHERE [Schedule Data].[ApptDate] = #" & Me.[ApptDate] & "#"
I don't know if this is just a syntax issue or if I'm missing some bigger concept. Any help is appreciated. I'm happy to provide any additional needed info. Thanks!
edit: The full error message reads:
Syntax error in date in query expression '[Schedule Data].[ApptDate] = #'
Sorry for neglecting to include that in the original message.
My code should have been:
Me.ComboTimeList.RowSource =
"SELECT [Schedule Data].[ApptStart] & _
FROM [Schedule Data] & _
WHERE [Schedule Data].[ApptDate] = #" & Me.[ApptDate] & "#;"
Additionally, Me.[ApptDate] was returning "Null" because I had the code in the Change event instead of AfterUpdate event.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.