程序段如下:本人菜鸟程序调了好长时间了,现在急用啊!!在线等啊
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdinquire_Click()
Dim txtsql As String
Dim msgtext As String
Dim dd(4) As Boolean
Dim mrc As ADODB.Recordset
'组合sql语句
txtsql = "select * from worker_info where"
'判断是否选择胸卡号查询方式
If Check1(0).Value Then
If Trim(txtid.Text) = "" Then
smeg = "胸卡号不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtid.SetFocus
Exit Sub
Else
'判断输入胸卡号是否为数字
If Not IsNumeric(Trim(txtid.Text)) Then
MsgBox "胸卡号请输入数字!", vbOKOnly + vbExclamation, "警告"
Exit Sub
txtid.SetFocus
End If
dd(0) = True
'组合查询语句
txtsql = txtsql & "id='" & Trim(txtid.Text) & "'"
End If
End If
'判断是否选择姓名查询方式
If Check1(1).Value Then
If Trim(txtname.Text) = "" Then
smeg = "姓名不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtname.SetFocus
Exit Sub
Else
dd(1) = True
If dd(0) Then
'组合查询语句
txtsql = txtsql & "and name='" & txtname.Text & "'"
Else
txtsql = txtsql & "name='" & txtname.Text & "'"
End If
End If
End If
'判断是否选择工段查询方式
If Check1(2).Value Then
If Trim(txtgongduan.Text) = "" Then
smeg = "工段不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtgongduan.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Then
txtsql = txtsql & "and gongduan='" & txtgongduan.Text & "'"
Else
txtsql = txtsql & "gongduan='" & txtgongduan.Text & "'"
End If
End If
End If
'判断是否设置查询方式
If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then
MsgBox "请选择查询方式!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'查询所有满足条件的内容
txtsql = txtsql & "order by id'"
Set mrc = executesql(txtsql, msgtext)
With myflexgrid1
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "姓名"
.TextMatrix(1, 1) = "胸卡号"
.TextMatrix(1, 2) = "性别"
.TextMatrix(1, 3) = "出生日期"
.TextMatrix(1, 4) = "工段"
.TextMatrix(1, 5) = "职务"
.TextMatrix(1, 6) = "政治面貌"
.TextMatrix(1, 7) = "文化程度"
Do While Not mrc.EOF 报错'91'对象变量或with块变量未设置
.Rows = Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = Format(mrc.Fields(3), "yyyy-mm-dd")
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
.TextMatrix(.Rows - 1, 6) = mrc.Fields(6)
.TextMatrix(.Rows - 1, 7) = mrc.Fields(7)
mrc.MoveNext
Loop
End With
mrc.Close
End Sub