将日期字段上的过滤器应用到子表单时,我遇到了一些问题,表格/表格和PC上的日期和时间格式为dd / mm / yyyy。我有一个函数是按下按钮时调用。我的代码如下所示:
Function ThisMonth()
Dim strFilter3 As String
Dim dDate as String
dDate = Format(Date - Day(Date) + 1, "dd/mm/yyyy")
strFilter3 = "[Data] > #" & dDate & "#"
' Or I am trying to apply it like this , I tried to see what I get from dDate and dDate2 with MsgBox.
' SECOND OPTION :
'dDate = "01/" & Month(Date) & "/" & Year(Date)
'dDate2 = Format(dDate, "dd/mm/yyyy")
'strFilter3 = "[Data] > #" & dDate2 & "#"
Forms!frmLogistica!sfrmLogistica.Form.Filter = strFilter3
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = True
'Date return the date of today 27/11/2015 while Day(date) return the day 27
End Function
当过滤器应用了这两个选项中的任何一个时,我看到过滤器应用如下:> 2015年11月1日[mm / dd / yyyy] [2015年1月1日] [dd / mm / yyyy]。
我试图宣布dDate& dDate2为String或Date但没有任何变化.... 我希望我明确了解细节,我的事情很容易格式化,我读了很多东西,但找不到合适的选项....我将尝试从文本框中获取值看看我用这样的命令弄清楚了什么:
strFilter3 = "[Data] > #" & Me.txtASD & "#"
最后,我想对今日/本周/本月/所有时间的子表单进行过滤。 My Today功能运行良好,看起来像这样:
Function Today()
Dim dDate As String
dDate = Format(Date, "dd/mm/yyyy")
strFilter2 = "[Data] = #" & dDate & "#"
Forms!frmLogistica!sfrmLogistica.Form.Filter = strFilter2
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = True
End Function
答案 0 :(得分:0)
我发现问题是什么,现在它起作用了,不得不改变格式(dDate,“mm / dd / yyyy”)并用BETWEEN&和。我终于使函数工作,因为我想要它们,我发布代码希望有人知道:D
frmLogistica - MainForm
sfrmLogistica - SubForm
Forms!MainForm!SubForm.Form.Filter它可以用Me.SubForm.Form.Filter替换
Function Today()
Dim dDate As String
dDate = Format(Date, "dd/mm/yyyy")
strFilter2 = "[Data] = #" & dDate & "#"
Forms!frmLogistica!sfrmLogistica.Form.Filter = strFilter2
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = True
End Function
Function ThisWeek()
dDate = Format(Date - 2, "mm/dd/yyyy")
dDate2 = Weekday(dDate)
dDate3 = Date - dDate2
dDate4 = Format(Date - 1, "mm/dd/yyyy")
dDate5 = Weekday(dDate4)
dDate6 = 7 - dDate5
dDate7 = Date + dDate6
strFilter3 = "[Data] between #" & dDate3 & "# AND #" & dDate7 & "#"
Me.Refresh
Forms!frmLogistica!sfrmLogistica.Form.Filter = strFilter3
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = True
End Function
Function ThisMonth()
dDate = Date - Day(Date) + 1
dDate2 = DateSerial(Year(Date), Month(Date) + 1, 0)
dDate3 = Format(dDate, "mm/dd/yyyy")
dDate4 = Format(dDate2, "mm/dd/yyyy")
strFilter3 = "[Data] between #" & dDate3 & "# AND #" & dDate4 & "#"
Me.Refresh
Forms!frmLogistica!sfrmLogistica.Form.Filter = strFilter3
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = True
End Function
Function ThisYear()
dDate = "1/1/" & Year(Date)
dDate2 = "31/12/ " & Year(Date)
dDate3 = Format(dDate, "mm/dd/yyyy")
dDate4 = Format(dDate2, "mm/dd/yyyy")
strFilter3 = "[Data] between #" & dDate3 & "# AND #" & dDate4 & "#"
Me.Refresh
Forms!frmLogistica!sfrmLogistica.Form.Filter = strFilter3
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = True
End Function
Function All()
Forms!frmLogistica!sfrmLogistica.Form.FilterOn = False
End Function