Below, the following lines of code exist.
On Error GoTo skip1
Application.Documents.Open
PFile
The purpose for this code is in the event the system cannot find the drawing on the server to open. In this case, it is supposed to skip and move to the next file. The logic works, un less there is more than one file that cannot be found, in which case the following runtime error occurs:
Runtime Error -'2145320924 (80210024)'
Method 'Open' of Object 'IAcadDocuments' failed.
Remember, this logic workled great the first time, and even after the first file cannot be found. It's when the second file cannot be found that thyere is a problem. I've tried to move the 'On Error' statement to above the Do While loop, but have gotten the same results.
Thanks in advance for any help you can provide.
............Start of Code
Private Sub cmdProcess_Click()
If Len(Me.cboJobNo.Value) = 0 Then
MsgBox "Job No must be selected first."
Me.cboJobNo.SetFocus
Exit Sub
End If
If rs.State = 1 Then rs.Close
If Len(cboJobNo.Value) = 0 Then
MsgBox "No Job Number Specified"
JNX = Me.cboJobNo.Value
SNX = Me.cboSubAssy.Value
SPX = Me.chkSP1.Value
FPX = Me.chkFPB1.Value
UserForm_Activate
Exit Sub
End If
If Len(cboSubAssy.Value) = 0 Then
MsgBox "No Sub Assembly Specified"
JNX = Me.cboJobNo.Value
SNX = Me.cboSubAssy.Value
SPX = Me.chkSP1.Value
FPX = Me.chkFPB1.Value
UserForm_Activate
Exit Sub
End If
If chkSP1.Value = False And chkFPB1.Value = False Then
MsgBox "No Plot Options Selected"
JNX = Me.cboJobNo.Value
SNX = Me.cboSubAssy.Value
SPX = Me.chkSP1.Value
FPX = Me.chkFPB1.Value
UserForm_Activate
Exit Sub
End If
Dim sqlPartNo As String
sqlPartNo = "SELECT tblBOM.PartNo, tblBOM.SubAssy, tblBOM.PartNo, tblPartsListing.Manufactur
edBy FROM tblPartsListing " & _
"INNER JOIN tblBOM ON tblPartsListing.PartNo = tblBOM.PartNo " & _
"WHERE (((tblBOM.JobNo) = " & Me.cboJobNo.Value & ") AND " & _
"((tblBOM.SubAssy) = '" & Me.cboSubAssy.Value & "') AND " & _
"((tblPartsListing.Manufac
turedBy) = '" & "METRO MACHINE" & "'))"
Debug.Print "sqlPartNo: " & sqlPartNo
rs.Open sqlPartNo, sConn, adOpenKeyset, adLockOptimistic
On Error GoTo skip2
rs.MoveFirst
Debug.Print rs.RecordCount
Dim PN As String
Dim PATH1 As String
Dim PATH2 As String
Do While Not rs.EOF
PN = rs.Fields("PartNo")
' Condition to elliminate the "-n" from PartNo
Dim PNR As String
PNR = Right(PN, 2)
Dim PNL As String
PNL = Left(PNR, 1)
If PNL = "-" Then
PN = Left(PN, (Len(PN) - 2))
End If
' Condition to ellim inate the "L or "R" from PartNo
PNR = Right(PN, 1)
If PNR = "L" Or PNR = "R" Then
PN = Left(PN, (Len(PN) - 1))
End If
' Determine file location per filename
JN = Left(PN, 5)
PATH1 = "\\deepblue\Projects\"
If Int(Right(JN, 2)) >= 50 Then
PATH2 = Left(JN, 3) & "50-" & Left(JN, 3) & "99\"
Else
PATH2 = Left(JN, 3) & "00-" & Left(JN, 3) & "49\"
End If
PATH3 = PATH1 & PATH2
FindFolderName (JN)
Dim PFile As String
PFile = PATH4 & PN & ".dwg"
Debug.Print PFile
On Error GoTo skip1
Application.Documents.Open
PFile
If chkSP1.Value = True And chkFPB1.Value = False Then
ThisDrawing.SendCommand "(setq PLOTYES" & Chr(34) & "Y" & Chr(34) & ")" & vbCr
ThisDrawing.SendCommand "(setq noprev 0)" & vbCr
ThisDrawing.SendCommand "SP1" & vbCr
ThisDrawing.Close
End If
If chkSP1.Value = False And chkFPB1.Value = True Then
ThisDrawing.SendCommand "(setq PLOTYES" & Chr(34) & "Y" & Chr(34) & ")" & vbCr
ThisDrawing.SendCommand "(setq noprev 0)" & vbCr
ThisDrawing.SendCommand "FPB1" & vbCr
ThisDrawing.Close
End If
If chkSP1.Value = True And chkFPB1.Value = True Then
ThisDrawing.SendCommand "(setq PLOTYES" & Chr(34) & "Y" & Chr(34) & ")" & vbCr
ThisDrawing.SendCommand "(setq noprev 0)" & vbCr
ThisDrawing.SendCommand "SP1" & vbCr
ThisDrawing.SendCommand "FPB1" & vbCr
ThisDrawing.Close
End If
GoTo skip3
skip1:
Me.lstMissedPlots.AddItem PN
rs.MoveNext
GoTo skip4
skip3:
Me.lstPlotted.AddItem PN
rs.MoveNext
skip4:
Loop
MsgBox "Plots are Complete!"
rs.Close
Exit Sub
skip2:
MsgBox "No Records..."
rs.Close
End Sub
Start Free Trial