這張圖只是查詢畫面時:圖下方是access 開啟資料表中共有5筆, 圖上方是 vb6 用datagrid卻只有顯示出前4筆. 我以前沒遇到這情形, (以前 clipper語言中, 有一個指令 commit 就是專門將最後一筆 buffer強迫寫入 , vb6 中倒沒這種指令.)
所以覺得很奇怪.
---源碼貼出如下 (很單純的查詢所寄出的 e-mail電子報 ) 如下------------------------
(grdEDM 就是DATAGRID的控制項 )
(DTPicker(0) DTPicker(1) 就是查詢日期 開始和結束)
(資料表EDM 中 有一欄位 UseTime 是文字型態 放比對的日期)
(下方quote 源碼內容 奇怪會變成沒縮排 有點難以閱讀 , 不知道如何貼源碼才會變成有縮排 )
語法:
'查詢
Private Sub cmd_Search_Click()
On Error Resume Next
Dim strSDate As String, strEDate As String, dateTemp As Date
Dim strRet As String
Dim varRet() As String
Dim varData() As String
Dim intType As Integer
Dim strMsg As String
Dim strStatus As String
Dim i As Long, j As Long
Me.MousePointer = 11
cmd_Search.Enabled = False
ReDim aryEID(0)
If Opt1(0).Value = True Then '24小時內
strSDate = Format(DateAdd("d", -1, Now), "yyyy/mm/dd hh:mm")
strEDate = Format(Now, "yyyy/mm/dd hh:mm")
ElseIf Opt1(1).Value = True Then '48小時內
strSDate = Format(DateAdd("d", -2, Now), "yyyy/mm/dd hh:mm")
strEDate = Format(Now, "yyyy/mm/dd hh:mm")
ElseIf Opt1(2).Value = True Then '72小時內
strSDate = Format(DateAdd("d", -3, Now), "yyyy/mm/dd hh:mm")
strEDate = Format(Now, "yyyy/mm/dd hh:mm")
ElseIf Opt1(3).Value = True Then '一週內
strSDate = Format(DateAdd("d", -7, Now), "yyyy/mm/dd hh:mm")
strEDate = Format(Now, "yyyy/mm/dd hh:mm")
ElseIf Opt1(4).Value = True Then '查詢區間
If DTPicker(0) > DTPicker(1) Then '日期對調
dateTemp = DTPicker(0)
DTPicker(0) = DTPicker(1)
DTPicker(1) = dateTemp
End If
strSDate = Format(DTPicker(0), "yyyy/mm/dd hh:mm") '注意==> 一定要加Format 變更格式"yyyy/mm/dd hh:mm" 否則查不出資料
strEDate = Format(DTPicker(1), "yyyy/mm/dd hh:mm")
End If
If strSDate = "//" Then strSDate = ""
If strEDate = "//" Then strEDate = ""
If strSDate = "" And strEDate = "" Then
MsgBox "請輸入查詢區間!", vbExclamation
Me.MousePointer = 0
cmd_Search.Enabled = True
Exit Sub
End If
txt_Msg.Text = ""
If SSTab1.Tab = 0 Then intType = 0
If SSTab1.Tab = 1 Then intType = 1
grd.Visible = False
grdEDM.Visible = False
grd_List.Visible = False
Select Case intType
Case 0 '簡訊-資料在SERVER端 ->下載後放入Temp_EDM
Case 1 '電子報 -資料在本機OnlyYou.mdb 中的 EDM
'MsgBox strSDate & vbCrLf & strEDate
SQL = "Select * From EDM Where UserID = '" & UserID & "' And EdmID = 0 "
If strSDate <> "" Then SQL = SQL & "And UseTime >= '" & strSDate & " 00:00:00' "
If strEDate <> "" Then SQL = SQL & "And UseTime <= '" & strEDate & " 23:59:59' "
SQL = SQL & "Order By SID Desc"
Debug.Print SQL
Set Rs = objSQL.SelecRs(SQL, ErrNum, ErrDescription)
If Not Rs.EOF Then
Set grdEDM.DataSource = Rs
grdEDM.Refresh
grdEDM.Refresh
grdEDM.Visible = True
Rs.MoveFirst
Else
MsgBox "無符合條件的資料 !"
End If
'Rs.Close '注意==>不可以CLOSE 否則畫面無法顯示資料
End Select
cmd_Search.Enabled = True
Me.MousePointer = 0
tmpEID = 0
End Sub