VB里的问题我这段查询是在一个文本框里显示的.我想改成表格形式的.Private Sub Command2_Click()'查询If Combo1.Text = "" ThenMsgBox "你没有选择查询方式,请选择!",16,"错误提示!"Exit SubEnd IfIf Combo1 "全部记
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 07:13:54
VB里的问题我这段查询是在一个文本框里显示的.我想改成表格形式的.Private Sub Command2_Click()'查询If Combo1.Text = "" ThenMsgBox "你没有选择查询方式,请选择!",16,"错误提示!"Exit SubEnd IfIf Combo1 "全部记
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
VB里的问题我这段查询是在一个文本框里显示的.我想改成表格形式的.Private Sub Command2_Click()'查询If Combo1.Text = "" ThenMsgBox "你没有选择查询方式,请选择!",16,"错误提示!"Exit SubEnd IfIf Combo1 "全部记
'添加一个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