我有一个表单从SQL Server表中提取数据。表单有两个未绑定的组合框。用户首先从comboName中选择,然后选择comboDate,然后表单将检索与值相关联的记录。
'comboDate AfterUpdate VBA macro
DoCmd.SearchForRecord , "", acFirst, "[Name] = " & "'" & comboName.Value & "'" & _
" and [Date] = " & "'" & Format(comboDate, "yyyy-mm-dd") & "'"
如果我单独使用Name = comboName.Value
,它将检索该名称的第一条记录,但如果我添加Date
条件,或使用Date
条件而不使用Name
,组合框将不再检索记录。它只停留在当前的一个。我已经转换了Access日期格式以匹配SQL Server。还有什么需要做的?
答案 0 :(得分:0)
Access needs #
symbols for it to recognize it as a date. It works when I change the query to this.
'comboDate AfterUpdate VBA macro
DoCmd.SearchForRecord , "", acFirst, "[Name] = " & "'" & comboName.Value & "'" & _
" and [Date] = " & "#" & Format(comboDate, "yyyy-mm-dd") & "#"