VB里的問題我這段查詢是在一個文本框裡顯示的.我想改成表格形式的.Private Sub Command2_Click(

題目:

VB里的問題
我這段查詢是在一個文本框裡顯示的.我想改成表格形式的.
Private Sub Command2_Click()
'查詢
If Combo1.Text = "" Then
MsgBox "你沒有選擇查詢方式,請選擇!",16,"錯誤提示!"
Exit Sub
End If
If Combo1 "全部記錄" And Text4.Text = "" Then
MsgBox "你沒有填寫查詢的關鍵字,請填寫!",16,"錯誤提示!"
Exit Sub
End If
Dim XX As Integer,SS As Integer
XX = 0:SS = 0:Text5.Text = "日 期" & Space(20) & "購買單位" & Space(16) & "用戶單位" & Space(10) & "聯繫人" & Space(10) & "聯繫電話" & Space(10) & vbCrLf
Call SJK(db)
RS.Open "Select * From 表1",db,3,3
SS = RS.RecordCount
RS.Close
Set RS = Nothing
If Combo1.Text = "全部記錄" Then
txtSQL = "Select * From 表1"
ElseIf Combo1.Text = "以姓名查詢" Then
txtSQL = "Select * From 表1 Where T2 Like '%" & Text4.Text & "%'"
ElseIf Combo1.Text = "以內容查詢" Then
txtSQL = "Select * From 表1 Where T3 Like '%" & Text4.Text & "%'"
End If
RS.Open txtSQL,db,2,2
Do While Not RS.EOF
XX = XX + 5
Text5.Text = Text5.Text & RS!T1 & 16 & RS!T2 & vbCrLf
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
db.Close
Set db = Nothing
If SS > 0 Then
If XX = 0 Then
MsgBox "對不起!你選擇方式中的關鍵字可能有誤,沒有你查詢的記錄!請重新查詢!",48,"無記錄!"
End If
Else
MsgBox "對不起!你的資料庫中沒有記錄,請首先錄入記錄!",48,"資料庫是空的!"
End If
End Sub
Public Sub SJK(db)
db.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);dbQ=" & App.Path & "\ABCD.mdb"
db.Open
End Sub
Private Sub Command3_Click()
Unload Me
其他查詢.Show
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
Private Sub MSFlexGrid1_Click()
End Sub

解答:

'添加一個MSFlexGrid1把
'Do While Not RS.EOF
'XX = XX + 5
'Text5.Text = Text5.Text & RS!T1 & 16 & RS!T2 & vbCrLf
'RS.MoveNext
'Loop
'RS.Close
'這段改爲:
With MSFlexGrid1
.FixedCols = 0
.FixedRows = 1
.Cols = 5
.FormatString = "日 期|購買單位|用戶單位|聯繫人|聯繫電話"
.ColWidth(0) = 2000 '列寬(數值自己修改)
.ColWidth(1) = 2000
.ColWidth(2) = 2000
.ColWidth(3) = 2000
.ColWidth(4) = 2000
Dim i As Integer
Do While Not RS.EOF
XX = XX + 5
i = i + 1
If i >= .Rows Then .Rows = i + 1
.TextMatrix(i, 1) = RS!T1 '不知道你的T1 T2是第幾列的值自己修改吧
.TextMatrix(i, 2) = RS!T2
RS.MoveNext
Loop
RS.Close
End With

添加新評論

暱稱
郵箱
網站