以下是我编的一个组合查询代码,可运行后提示对象变量或with块变量未设置,该怎么处理?
Private Sub chaxunCmd_Click()
Dim txtSQL As StringDim dd(4) As Boolean
txtSQL = "select * from dfchzh where "
If carChk.Value Then
If Trim(Txt1.Text) = "" Then
sMeg = "车号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Txt1.SetFocus
Exit SubEnd If
dd(0) = True
txtSQL = txtSQL & "车号 = '" & Trim(Txt1.Text) & "'"End IfIf lacChk.Value Then
If Trim(Txt2.Text) = "" Then
sMeg = "贮物区不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Txt2.SetFocus
Exit Sub
Else
dd(1) = True
If dd(0) Then
txtSQL = txtSQL & "and 贮物区 = '" & Txt2.Text & "'"
Else
txtSQL = txtSQL & "贮物区 = '" & Txt2.Text & "'"
End If
End If
End IfIf dayChk.Value Then
If Trim(Txt3.Text) = "" Then
sMeg = "日期不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Txt3.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Then
txtSQL = txtSQL & "and 贮物区 = '" & Txt2.Text & "'"
Else
txtSQL = txtSQL & "贮物区 = '" & Txt2.Text & "'"
End If
End If
End IfIf Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then
MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End IftxtSQL = txtSQL & " order by 编号 "
Data1.RecordSource = txtSQL
With myflexgrid
.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) = "贮物区"
.TextMatrix(1, 8) = "毛重"
.TextMatrix(1, 9) = "皮重"
.TextMatrix(1, 10) = "净重"
Do While Not Data1.Recordset.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Data1.Recordset.Fields(0)
.TextMatrix(.Rows - 1, 1) = Data1.Recordset.Fields(1)
.TextMatrix(.Rows - 1, 2) = Data1.Recordset.Fields(2)
.TextMatrix(.Rows - 1, 3) = Data1.Recordset.Fields(3)
.TextMatrix(.Rows - 1, 4) = Data1.Recordset.Fields(4)
.TextMatrix(.Rows - 1, 5) = Data1.Recordset.Fields(5)
.TextMatrix(.Rows - 1, 6) = Data1.Recordset.Fields(6)
.TextMatrix(.Rows - 1, 7) = Data1.Recordset.Fields(7)
.TextMatrix(.Rows - 1, 8) = Data1.Recordset.Fields(8)
.TextMatrix(.Rows - 1, 9) = Data1.Recordset.Fields(9)
.TextMatrix(.Rows - 1, 10) = Data1.Recordset.Fields(10)
Data1.Recordset.MoveNext
Loop
End WithEnd Sub
Private Sub chaxunCmd_Click()
Dim txtSQL As StringDim dd(4) As Boolean
txtSQL = "select * from dfchzh where "
If carChk.Value Then
If Trim(Txt1.Text) = "" Then
sMeg = "车号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Txt1.SetFocus
Exit SubEnd If
dd(0) = True
txtSQL = txtSQL & "车号 = '" & Trim(Txt1.Text) & "'"End IfIf lacChk.Value Then
If Trim(Txt2.Text) = "" Then
sMeg = "贮物区不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Txt2.SetFocus
Exit Sub
Else
dd(1) = True
If dd(0) Then
txtSQL = txtSQL & "and 贮物区 = '" & Txt2.Text & "'"
Else
txtSQL = txtSQL & "贮物区 = '" & Txt2.Text & "'"
End If
End If
End IfIf dayChk.Value Then
If Trim(Txt3.Text) = "" Then
sMeg = "日期不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Txt3.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Then
txtSQL = txtSQL & "and 贮物区 = '" & Txt2.Text & "'"
Else
txtSQL = txtSQL & "贮物区 = '" & Txt2.Text & "'"
End If
End If
End IfIf Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then
MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End IftxtSQL = txtSQL & " order by 编号 "
Data1.RecordSource = txtSQL
With myflexgrid
.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) = "贮物区"
.TextMatrix(1, 8) = "毛重"
.TextMatrix(1, 9) = "皮重"
.TextMatrix(1, 10) = "净重"
Do While Not Data1.Recordset.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Data1.Recordset.Fields(0)
.TextMatrix(.Rows - 1, 1) = Data1.Recordset.Fields(1)
.TextMatrix(.Rows - 1, 2) = Data1.Recordset.Fields(2)
.TextMatrix(.Rows - 1, 3) = Data1.Recordset.Fields(3)
.TextMatrix(.Rows - 1, 4) = Data1.Recordset.Fields(4)
.TextMatrix(.Rows - 1, 5) = Data1.Recordset.Fields(5)
.TextMatrix(.Rows - 1, 6) = Data1.Recordset.Fields(6)
.TextMatrix(.Rows - 1, 7) = Data1.Recordset.Fields(7)
.TextMatrix(.Rows - 1, 8) = Data1.Recordset.Fields(8)
.TextMatrix(.Rows - 1, 9) = Data1.Recordset.Fields(9)
.TextMatrix(.Rows - 1, 10) = Data1.Recordset.Fields(10)
Data1.Recordset.MoveNext
Loop
End WithEnd Sub
解决方案 »
- VB怎样更改treeview前面复先框的图标
- 取messagebox弹出的信息
- 大家帮忙看看这段ORACLE多表查询该怎么写!
- 第一次做文件格式转换,麻烦给点思路,谢谢
- 请问有关InstallShield的问题(我知道我问错地方了,但这个问题没地方问)
- 高手帮忙看段代码?
- 怎么把这些字符串转化成汉字啊??
- 使用 ADOX 是否能将已经存在的字段设置为主键 以及 将已被设置为主键的字段取消主键属性 ?
- 执行SQL语句有几种方法?
- object.ExportData( BulkCopy ) 的object只能是表名吗?——急!!!
- 如何控制textbox的输入长度 MaxLength只能计算输入的字母长度,怎么控制文字和字母混合输入时的长度
- 取得表的名称?出错了请大家帮忙!!
详细点
你调试一下他的SQL语句。一般SQL语句爱出问题。Data1 记录集没打开。如果是ADO就这样提示。