简体   繁体   中英

MS Access SELECT DISTINCT WHERE query as combobox row source

I want to simplify a bit of code I've been working on in a MS Access 2010 database I've inherited. I want the user to enter a date in a form in a field [txtSelectDate], and then select from a combobox any [ProductName] for which a record is in the [uploads] table on the user's selected date.

Currently I have a special query designed to do that, but I was brushing up on my SQL and I wondered if I could do it completely within an SQL expression in the Property Sheet> Data > Row Source field.

My attempt was:

SELECT DISTINCT [Uploads].[ProductName] 
FROM Uploads 
WHERE [Uploads].[ImportDate] = [Forms]![Review]![txtSelectDate] 
ORDER BY [ProductName];

Which feels to me like it should work, but it gives me a blank combo with no options in it. If I take away the WHERE, I get options, but I get every option, regardless of if the [ProductName] value in question was actually in the Uploads on the date selected.

I think you need to refresh your form after the date is entered- assuming they're on the same form, add an after update event to your text box:

Private Sub txtSelectDate_AfterUpdate()
    Me.refresh
End Sub

检查您的txtSelectDate是否正确转换为Date类型(或至少与Uploads.ImportDate匹配,无论它是什么类型),或者您的查询将返回零行?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM