主题:紧急求救!!!对象变量或With块变量未设置
[color=0000FF]小弟给单位部室做了一个工资资料的管理系统,在进行浏览时出现了“实时错误91,对象变量或With块变量未设置”。因为小弟本不是学计算机专业的,就是凭着大学选修学过的那一点点VB知识,做了这个系统,希望各位大虾们帮帮小弟!!!小弟在线等!!![/color]
具体代码如下:
Public printstr As String
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Sub showtitle()
Dim i As Integer
MSF1.Clear
With MSF1
.Cols = 14
.TextMatrix(0, 1) = "工程名称"
.TextMatrix(0, 2) = "施组(方案)名称"
.TextMatrix(0, 3) = "编制时间"
.TextMatrix(0, 4) = "报审时间"
.TextMatrix(0, 5) = "审批时间"
.TextMatrix(0, 6) = "实际报审时间"
.TextMatrix(0, 7) = "实际审批时间"
.TextMatrix(0, 8) = "审批状态"
.TextMatrix(0, 9) = "项目部会签表"
.TextMatrix(0, 10) = "公司会签表"
.TextMatrix(0, 11) = "公司审批表"
.TextMatrix(0, 12) = "监理报审表"
.TextMatrix(0, 13) = "备注"
.ColWidth(0) = 100
.ColWidth(1) = 2000
.ColWidth(2) = 1500
.ColWidth(3) = 1000
.ColWidth(4) = 1000
.ColWidth(5) = 1000
.ColWidth(6) = 1500
.ColWidth(7) = 1500
.ColWidth(8) = 1000
.ColWidth(9) = 1500
.ColWidth(10) = 1500
.ColWidth(11) = 1500
.ColWidth(12) = 1500
.ColWidth(13) = 800
.FixedRows = 1
For i = 1 To 12
.ColAlignment(i) = 0
Next i
.FillStyle = flexFillSingle
.Col = 0
.Row = 0
.RowSel = 1
.ColSel = .Cols - 1
.CellAlignment = 4
.Row = 1
End With
End Sub
Private Sub Form_Activate()
If find = True Then
施组方案查询.ZOrder
Exit Sub
ElseIf modi = True Then
showdata
' TreeView1_DblClick
modi = False
Else
classtree
End If
'If classfind = True Then
' Exit Sub
'Else
' MDIForm1.clabrowse
'End If
End Sub
Public Sub showdata()
Dim j As Integer
Dim i As Integer
Dim mrc As ADODB.Recordset
Set mrc = ExecuteSQL(Trim(txtsql))
[color=FF0000][b]If mrc.EOF = False Then(提示这句有问题!!!)[/b][/color]
mrc.MoveFirst
With MSF1
.Rows = 1
.Row = 1
Do While Not mrc.EOF
.Rows = .Rows + 1
For i = 1 To mrc.Fields.Count
.TextMatrix(.Row, i) = mrc.Fields(i - 1)
Next i
.Row = .Row + 1
mrc.MoveNext
Loop
End With
Else
If find = True Then
Form3.Hide
Form4.Show
zzz = MsgBox("对不起,没有此项记录!", vbOKOnly, "查询")
Form4.ZOrder (0)
Form4.Text1(0).SetFocus
End If
End If
Set mrc = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
If find = True Then
find = False
施组方案查询.Text1(0).SetFocus
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Tag
Case "find"
施组方案查询.Show
Case "modi"
If Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) = "" Then
sssss = MsgBox("你还没有选择记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
Else
qxstr = Executeqx(2)
If qxstr = "readonly" Then
ss = MsgBox("对不起,你是只读用户不能修改记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告")
Exit Sub
End If
modi = True
施组方案添加.Show
施组方案添加.ZOrder 0
End If
Case "del"
Dim mrc As ADODB.Recordset
Dim intcount As Integer
If Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) = "" Then
sssss = MsgBox("你还没有选择记录!", vbOKOnly + vbExclamation, "警告")
Else
If qxstr = "readonly" Then
ss = MsgBox("对不起,你是只读用户不能删除记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告")
Exit Sub
End If
If MsgBox("确定要删除" & Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) & "工程的 " & Trim(Me.MSF1.TextMatrix(MSF1.Row, 2)) & " 记录吗?" & Chr(10) & Chr(13) & "该操作会导致此工程的该施组(方案)记录的丢失!确定吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
intcount = Me.MSF1.Row
txtsql = "delete * from xj where (工程名称='" & Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) & "' and 施组(方案)名称='" & Trim(Me.MSF1.TextMatrix(MSF1.Row, 2)) & "')"
Set mrc = ExecuteSQL(txtsql)
TreeView1_DblClick
End If
End If
' Case "print"
' Form6.Show
' Form6.ZOrder 0
End Select
End Sub
Public Sub classtree()
TreeView1.Nodes.Clear
Dim nodex As Node
Dim mrc As ADODB.Recordset
Dim mrc1 As ADODB.Recordset
Dim str As String
Dim a As String
a = "项目名称"
TreeView1.LineStyle = tvwRootLines
str = "select distinct 项目名称 from class order by 项目名称"
Set mrc = ExecuteSQL(str)
str = "select distinct 项目名称,工程名称 from class order by 项目名称,工程名称"
Set mrc1 = ExecuteSQL(str)
mrc.MoveFirst
Do Until mrc.EOF
mrc1.MoveFirst
Set nodex = TreeView1.Nodes.add(, , a, mrc.Fields(0), 1, 1)
Do While Not mrc1.EOF
If mrc1.Fields(0) = mrc.Fields(0) Then
Set nodex = TreeView1.Nodes.add(a, tvwChild, , mrc1.Fields(1), 2, 2)
End If
mrc1.MoveNext
Loop
a = a & "1"
mrc.MoveNext
Loop
mrc1.Close
mrc.Close
Set mrc = Nothing
Set mrc1 = Nothing
End Sub
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
Select Case ButtonMenu.Key
Case "dang"
If Trim(printstr) = "" Then
sssss = MsgBox("没有当前记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
If DataEnv1.rsCommand1.State = adStateOpen Then
DataEnv1.rsCommand1.Close
End If
DataEnv1.rsCommand1.Open printstr
If DataEnv1.rsCommand1.EOF = True Then
sssss = MsgBox("没有当前记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
DataReportclass.Show 1
Case "all"
If DataEnv1.rsCommand1.State = adStateOpen Then
DataEnv1.rsCommand1.Close
End If
DataEnv1.rsCommand1.Open ("select class.工程名称,xj.施组(方案)名称,xj.编制时间,xj.报审时间,xj.审批时间,xj.实际报审时间,xj.实际报审时间,xj.审批状态,xj.项目部会签表,xj.公司会签表,xj.公司审批表,xj.监理报审表,xj.备注 from xj inner join class on xj.工程名称=class.工程名称")
If DataEnv1.rsCommand1.EOF = True Then
sssss = MsgBox("没有当前记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
DataReportclass.Show 1
End Select
End Sub
Private Sub TreeView1_DblClick()
On Error GoTo ss
If TreeView1.SelectedItem.Index = 0 Then
MSF1.Clear
Exit Sub
End If
txtsql = TreeView1.Nodes.Item(TreeView1.SelectedItem.Index)
txtsql = " select xj.工程名称,xj.施组(方案)名称,xj.编制时间,xj.报审时间,xj.审批时间,xj.实际报审时间,xj.实际报审时间,xj.审批状态,xj.项目部会签表,xj.公司会签表,xj.公司审批表,xj.监理报审表,xj.备注"
printstr = txtsql
Me.Caption = "浏览施组方案"
Me.showtitle
Me.showdata
Exit Sub
ss:
MSF1.Clear
End Sub
具体代码如下:
Public printstr As String
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Sub showtitle()
Dim i As Integer
MSF1.Clear
With MSF1
.Cols = 14
.TextMatrix(0, 1) = "工程名称"
.TextMatrix(0, 2) = "施组(方案)名称"
.TextMatrix(0, 3) = "编制时间"
.TextMatrix(0, 4) = "报审时间"
.TextMatrix(0, 5) = "审批时间"
.TextMatrix(0, 6) = "实际报审时间"
.TextMatrix(0, 7) = "实际审批时间"
.TextMatrix(0, 8) = "审批状态"
.TextMatrix(0, 9) = "项目部会签表"
.TextMatrix(0, 10) = "公司会签表"
.TextMatrix(0, 11) = "公司审批表"
.TextMatrix(0, 12) = "监理报审表"
.TextMatrix(0, 13) = "备注"
.ColWidth(0) = 100
.ColWidth(1) = 2000
.ColWidth(2) = 1500
.ColWidth(3) = 1000
.ColWidth(4) = 1000
.ColWidth(5) = 1000
.ColWidth(6) = 1500
.ColWidth(7) = 1500
.ColWidth(8) = 1000
.ColWidth(9) = 1500
.ColWidth(10) = 1500
.ColWidth(11) = 1500
.ColWidth(12) = 1500
.ColWidth(13) = 800
.FixedRows = 1
For i = 1 To 12
.ColAlignment(i) = 0
Next i
.FillStyle = flexFillSingle
.Col = 0
.Row = 0
.RowSel = 1
.ColSel = .Cols - 1
.CellAlignment = 4
.Row = 1
End With
End Sub
Private Sub Form_Activate()
If find = True Then
施组方案查询.ZOrder
Exit Sub
ElseIf modi = True Then
showdata
' TreeView1_DblClick
modi = False
Else
classtree
End If
'If classfind = True Then
' Exit Sub
'Else
' MDIForm1.clabrowse
'End If
End Sub
Public Sub showdata()
Dim j As Integer
Dim i As Integer
Dim mrc As ADODB.Recordset
Set mrc = ExecuteSQL(Trim(txtsql))
[color=FF0000][b]If mrc.EOF = False Then(提示这句有问题!!!)[/b][/color]
mrc.MoveFirst
With MSF1
.Rows = 1
.Row = 1
Do While Not mrc.EOF
.Rows = .Rows + 1
For i = 1 To mrc.Fields.Count
.TextMatrix(.Row, i) = mrc.Fields(i - 1)
Next i
.Row = .Row + 1
mrc.MoveNext
Loop
End With
Else
If find = True Then
Form3.Hide
Form4.Show
zzz = MsgBox("对不起,没有此项记录!", vbOKOnly, "查询")
Form4.ZOrder (0)
Form4.Text1(0).SetFocus
End If
End If
Set mrc = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
If find = True Then
find = False
施组方案查询.Text1(0).SetFocus
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Tag
Case "find"
施组方案查询.Show
Case "modi"
If Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) = "" Then
sssss = MsgBox("你还没有选择记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
Else
qxstr = Executeqx(2)
If qxstr = "readonly" Then
ss = MsgBox("对不起,你是只读用户不能修改记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告")
Exit Sub
End If
modi = True
施组方案添加.Show
施组方案添加.ZOrder 0
End If
Case "del"
Dim mrc As ADODB.Recordset
Dim intcount As Integer
If Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) = "" Then
sssss = MsgBox("你还没有选择记录!", vbOKOnly + vbExclamation, "警告")
Else
If qxstr = "readonly" Then
ss = MsgBox("对不起,你是只读用户不能删除记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告")
Exit Sub
End If
If MsgBox("确定要删除" & Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) & "工程的 " & Trim(Me.MSF1.TextMatrix(MSF1.Row, 2)) & " 记录吗?" & Chr(10) & Chr(13) & "该操作会导致此工程的该施组(方案)记录的丢失!确定吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
intcount = Me.MSF1.Row
txtsql = "delete * from xj where (工程名称='" & Trim(Me.MSF1.TextMatrix(MSF1.Row, 1)) & "' and 施组(方案)名称='" & Trim(Me.MSF1.TextMatrix(MSF1.Row, 2)) & "')"
Set mrc = ExecuteSQL(txtsql)
TreeView1_DblClick
End If
End If
' Case "print"
' Form6.Show
' Form6.ZOrder 0
End Select
End Sub
Public Sub classtree()
TreeView1.Nodes.Clear
Dim nodex As Node
Dim mrc As ADODB.Recordset
Dim mrc1 As ADODB.Recordset
Dim str As String
Dim a As String
a = "项目名称"
TreeView1.LineStyle = tvwRootLines
str = "select distinct 项目名称 from class order by 项目名称"
Set mrc = ExecuteSQL(str)
str = "select distinct 项目名称,工程名称 from class order by 项目名称,工程名称"
Set mrc1 = ExecuteSQL(str)
mrc.MoveFirst
Do Until mrc.EOF
mrc1.MoveFirst
Set nodex = TreeView1.Nodes.add(, , a, mrc.Fields(0), 1, 1)
Do While Not mrc1.EOF
If mrc1.Fields(0) = mrc.Fields(0) Then
Set nodex = TreeView1.Nodes.add(a, tvwChild, , mrc1.Fields(1), 2, 2)
End If
mrc1.MoveNext
Loop
a = a & "1"
mrc.MoveNext
Loop
mrc1.Close
mrc.Close
Set mrc = Nothing
Set mrc1 = Nothing
End Sub
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
Select Case ButtonMenu.Key
Case "dang"
If Trim(printstr) = "" Then
sssss = MsgBox("没有当前记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
If DataEnv1.rsCommand1.State = adStateOpen Then
DataEnv1.rsCommand1.Close
End If
DataEnv1.rsCommand1.Open printstr
If DataEnv1.rsCommand1.EOF = True Then
sssss = MsgBox("没有当前记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
DataReportclass.Show 1
Case "all"
If DataEnv1.rsCommand1.State = adStateOpen Then
DataEnv1.rsCommand1.Close
End If
DataEnv1.rsCommand1.Open ("select class.工程名称,xj.施组(方案)名称,xj.编制时间,xj.报审时间,xj.审批时间,xj.实际报审时间,xj.实际报审时间,xj.审批状态,xj.项目部会签表,xj.公司会签表,xj.公司审批表,xj.监理报审表,xj.备注 from xj inner join class on xj.工程名称=class.工程名称")
If DataEnv1.rsCommand1.EOF = True Then
sssss = MsgBox("没有当前记录!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
DataReportclass.Show 1
End Select
End Sub
Private Sub TreeView1_DblClick()
On Error GoTo ss
If TreeView1.SelectedItem.Index = 0 Then
MSF1.Clear
Exit Sub
End If
txtsql = TreeView1.Nodes.Item(TreeView1.SelectedItem.Index)
txtsql = " select xj.工程名称,xj.施组(方案)名称,xj.编制时间,xj.报审时间,xj.审批时间,xj.实际报审时间,xj.实际报审时间,xj.审批状态,xj.项目部会签表,xj.公司会签表,xj.公司审批表,xj.监理报审表,xj.备注"
printstr = txtsql
Me.Caption = "浏览施组方案"
Me.showtitle
Me.showdata
Exit Sub
ss:
MSF1.Clear
End Sub