我必須捕捉with塊內的錯誤。我正在讀取一個文件,並將其添加到表格中,然後將這些記錄添加到表格中。如果出現任何錯誤移到下一行文件On Error not in vba
Do Until EOF(1)
Line Input #1, strTextLine
'regex.replaces will replace the commas outside quotes with <???> and then the Split function will split the result based on our replacement
regex.Pattern = ",(?=([^""]*""[^""]*"")*(?![^""]*""))"
strArray = Split(regex.Replace(strTextLine, "<???>"), "<???>")
Set rs = db("ATC").OpenRecordset
With rs
.AddNew
On Error GoTo lpp
!ATC_ID = Replace(strArray(0), """", "")
!ATC_NAME = Replace(strArray(1), """", "")
.update
.Close
End With
lpp:
'goto next line in the file
Loop
看看[這裏](http://stackoverflow.com/a/41553765/4926357)或者[這裏](HTTP:// stackoverflow.com/a/42457284/4926357) –
@ASH已完成 – Faisal
如果此塊位於循環內部,您可能錯誤地處理了錯誤,請嘗試顯示一些循環的代碼。 –