版权声明:未经本人同意不得转载! https://blog.csdn.net/Hellen0708/article/details/83041482
干货
组合查询窗体中查询字段有日期有时间,那这样我们还用文本框来显示的话是不是用户体验很不好,本着提升用户体验的想法把文本框换成DTPicker控件。下面看看效果和怎么实现的。
功能是当点击需要输入日期时间的查询条件时,文本框自动转换为时间控件。时间控件要使用数组,利用循环语句减少代码量。
Private Sub comFields1_Click(Index As Integer)
Dim i As Integer
'设置时间控件
For i = 0 To 2
If comFields1(i).Text = "注册日期" Or comFields1(i).Text = "注销日期" Then
DTPicker1(i).Format = dtpCustom
DTPicker1(i).Visible = True
txtInquiry1(i).Visible = False
Else
If comFields1(i).Text = "注册时间" Or comFields1(i).Text = "注销时间" Then
DTPicker1(i).Format = dtpTime
DTPicker1(i).Visible = True
txtInquiry1(i).Visible = False
Else
txtInquiry1(i).Visible = True
DTPicker1(i).Visible = False
End If
End If
Next i
End Sub
再把组合查询的代码做一下小改动,这个功能就彻底实现了。下面放一段代码。
If DTPicker1(0).Visible = False Then
If Trim(comFields1(0).Text) = "" Or Trim(comOperator1(0).Text) = "" Or Trim(txtInquiry1(0).Text) = "" Then
MsgBox "请将第一行内容补充完整!", 48, "警告"
Else
txtSQL = txtSQL & " " & field(Trim(comFields1(0).Text)) & " " & Trim(comOperator1(0).Text) & "'" & Trim(txtInquiry1(0).Text) &""
End If
End If
If DTPicker1(0).Visible = True Then
If Trim(comFields1(0).Text) = "" Or Trim(comOperator1(0).Text) = "" Or Trim(DTPicker1(0).Value) = "" Then
MsgBox "请将第一行内容补充完整!", 48, "警告"
Else
txtSQL = txtSQL & " " & field(Trim(comFields1(0).Text)) & " " & Trim(comOperator1(0).Text) & "'" & Trim(DTPicker1(0).Value) & " '"
End If
End If