我的代码是:
=================
声明节声明
Dim StrLSB As String
----------------------------
Sub AllSub(PID As Integer)
Dim Str1 As String
' Dim StrLSB As String
Dim i As Integer
i = 1
ReCreateLSB:
On Error GoTo Err_AllSub
StrLSB = "LSB" & i
Str1 = "SELECT CategoryID INTO " & StrLSB & " FROM tblHWCategory WHERE ParentID=" + CStr(PID)
DoCmd.RunSQL Str1 '标记2
Exit_AllSub:
Exit Sub
Err_AllSub:
If err = 3211 Then
i = i + 1
GoTo ReCreateLSB '标记1
' Resume Next
Else
Resume Exit_AllSub
End If
End Sub
================
现在问题情况是:LSB1已被使用时,能够通过出错处理自动运行到标记1,然后返回继续运行,本想继续生成LSB2,但此时LSB2也被使用中,运行到标记2时再次出错。
问:1、出错处理是不是只能使用一次?如何循环出错处理?
或者,2、如何用VBA检测表LSB?正在被使用中?
[attach]46917[/attach] 作者: Henry D. Sy 时间: 2011-10-11 11:37
试试捕捉错误代码,
如果出现3211错误i自动+1试试作者: Henry D. Sy 时间: 2011-10-11 11:39
do until err =“”
i=i+1
loop作者: zww3008 时间: 2011-10-11 11:53
具体怎么应用?
do until err =“”
i=i+1
loop
代码放在哪?反复试了好像不行。作者: yehf 时间: 2011-10-11 12:24
试试这样
Sub AllSub(PID As Integer)
Dim Str1 As String
Dim StrLSB As String
Dim i As Integer
i = 1
'ReCreateLSB:
'On Error GoTo Err_AllSub
On Error Resume Next
Do While Err = 3211
StrLSB = "LSB" & i
Str1 = "SELECT CategoryID INTO " & StrLSB & " FROM tblHWCategory WHERE ParentID=" + CStr(PID)
DoCmd.RunSQL Str1 '标记2
i = i + 1
Loop
End Sub 作者: tmtony 时间: 2011-10-11 12:37
Do while Err.number<>0
'再加个超时多少秒,也退出
loop作者: tmtony 时间: 2011-10-11 12:38
Do while Err.number<>0
err.clear '清错误代码
'再加个超时多少秒,也退出
'你的处理代码
Dim Str1 As String
' Dim StrLSB As String
Dim i As Integer
i = 1
Do
err.Clear '清错误代码
StrLSB = "LSB" & i
Str1 = "SELECT CategoryID INTO " & StrLSB & " FROM tblHWCategory WHERE ParentID=" + CStr(PID)
DoCmd.SetWarnings False
DoCmd.RunSQL Str1
i = i + 1
'MsgBox err.Description
Loop While err.Number = 3211 And i < 50