我寫了一個需要一個搜索參數的hta應用程序。如何在.hta代碼中添加日期範圍?
使用此搜索參數,用戶可以通過名字或姓氏或兩者進行搜索。
這個功能非常好。
今天,管理層決定添加日期範圍作爲搜索的一部分。
我試圖構建WHERE子句,用戶可以使用姓氏,名字或兩者或日期範圍但不能同時搜索。
換句話說,一方面,用戶可以使用名爲txtsrch的表單變量來搜索姓氏,名字或兩者。
或者他們只能使用日期範圍,只能使用fromDAY作爲fromDate,toDAY作爲toDate。
到目前爲止,它工作得不好。
無論我在名稱搜索框中輸入搜索還是選擇日期範圍,都會出現類型不匹配錯誤。
當它僅僅是一個搜索框時,我沒有收到類型不匹配錯誤。
任何幫助,非常感謝。
這是最小的,我認爲相關的代碼。
日期是2013年1月1日
'*
Const cOPT = "<option value='?'>?</option>"
'*
Dim fromMDY(2)
Dim toMDY(2)
Dim optMDY(2)
optMDY(0) = "<option value='0'></option>"
optMDY(1) = "<option value='0'></option>"
optMDY(2) = "<option value='0'></option>"
Dim i
'*
For i = 1 To 12
optMDY(0) = optMDY(0) & vbCrLf & Replace(cOPT,"?",i)
Next
For i = 1 To 31
optMDY(1) = optMDY(1) & vbCrLf & Replace(cOPT,"?",i)
Next
For i = Year(Date)+1 To Year(Date)-4 Step -1
optMDY(2) = optMDY(2) & vbCrLf & Replace(cOPT,"?",i)
Next
Sub Selected(What)
Select Case What
Case "FromMonth"
fromMDY(0) = FromMonth.Value
Case "FromDay"
fromMDY(1) = FromDay.Value
Case "FromYear"
fromMDY(2) = FromYear.Value
Case "ToMonth"
toMDY(0) = ToMonth.Value
Case "ToDay"
toMDY(1) = ToDay.Value
Case "ToYear"
toMDY(2) = ToYear.Value
End Select
End Sub
Sub DisplayDates()
MsgBox "From:" & vbTab & Join(fromMDY,"/") & vbCrlf _
& "To:" & vbTab & Join(toMDY,"/")
End Sub
' first: Do we use AND or OR between clauses in the WHERE?
' AndOr = ANDOR.value
Sub radiocheck()
for each b in ANDOR
if b.checked Then AndOr = b.Value
next
End Sub
' and now build up the WHERE:
where = ""
tsrch = txtsrch.Value
If tsrch <> "" Then
where = where & " Name = '" & Replace(tsrch,"'","''") & "'"
End If
If fromMDY <> "" AND toMDY<> "" Then
where = where & " convert(datetime, (left(dispdt,2) + '/' + substring(dispdt,3,2) + '/' + case when cast(right(dispdt,2) as int) >= 70 then '19' else '20' end + right(dispdt,2)), 101) Between '"& fromMDY &"' AND '"& toMDY &"' "
End If
'Take care of sql injection tactics
SQL_query = "SELECT TOP 1000 Name, Rel, Estno, dtfild, pub, [TYPE OF DOCUMENT] typeofdocument, btyp, bkno, disp, dispdt, PGNO FROM PCS60418_MTHLY_XREF WHERE " _
& where
msgBox sql_query
嗨@Cheran,我看到你完全編輯了我的問題。 謝謝。我可以知道你改變了什麼,爲什麼? 謝謝 – Kenny
您可以點擊我名字上方的時間戳(例如,「編輯_21小時前_」)以查看修訂歷史記錄。我只是刪除了問候(它沒有給問題增加任何價值),並添加了語言提示,以便語法着色是正確的。 –