以下是我编的一个组合查询代码,可运行后提示对象变量或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