【问题标题】:Filter between two dates MS Access在两个日期之间过滤 MS Access
【发布时间】:2021-06-29 09:05:43
【问题描述】:

我有一个表单,我在其中创建了两个文本框来选择开始和结束日期,并创建了一个按钮来按所选日期过滤表单中的表格。

我的 vba 代码不起作用。有人可以帮忙吗?

这是代码:

Private Sub Command150_Click()
If IsNull(Me.Text153) And IsNull(Me.Text155) Then
    Me.FilterOn = False
Else
    Me.Filter = "[Datum] BETWEEN #" & Me.Text153 & "# AND #" & Me.Text155 & "#"
    Me.FilterOn = True
End If
 
End Sub

注意:Text153 是开始日期,Text 155 是结束日期,Datum 是表格中被过滤的字段。 过滤的日期应该是 >= 开始日期和

【问题讨论】:

    标签: vba ms-access filter


    【解决方案1】:

    Datum 听起来像是德语,因此您可能必须强制使用斜杠作为日期分隔符:

    Private Sub Command150_Click()
    
        Dim Filter  As String
    
        If IsNull(Me.Text153) Or IsNull(Me.Text155) Then
            Me.FilterOn = False
        Else
            Filter = "[Datum] BETWEEN #" & Format(Me.Text153, "yyyy\/mm\/dd") & "# AND #" & Format(Me.Text155, "yyyy\/mm\/dd") & "#"
            ' Print the filter string to the Immediate window (press Ctrl+G).
            Debug.Print Filter
            Me.Filter = Filter
            Me.FilterOn = True
        End If
     
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多