Hi everyone. I got these errors when I run my program. Can you please give me an direction how to fix it. I tried to import data from database and it show run-time error '52', I clicked on debug but it didn't go to debug screen then I exist the program and it show run-time error '35012'. Here is the code that I have. It used to work without any problem. Thank you.
[Code]
Sub ImportD11()
Dim LocationArray(3, 1)
'On Error GoTo ErrorFound
Open "C:\sbms\obj\reports\sips0003.nff" For Input As #1
'Line 1 (Crap)
Line Input #1, TmpString
'Line 2 (Date)
Line Input #1, TmpString
TmpString = Right(Trim(TmpString), 11)
Range("B1").Value = Left(TmpString, 6) + ", " + Right(TmpString, 4)
Range("B1").NumberFormat = "mm/dd/yyyy"
CurrentDate = Range("B1").Text
'First Record of Location File is Jan 1, 2002. 2nd is Jan 2nd, 2002... etc... etc...
Open ThisWorkbook.Path + "\" + LocationDB For Random As #5 Len = LocationLen
LocationRecord = DateDiff("d", "01/01/2002", CurrentDate) + 1
'Check to see whether current date has been run already
If LocationRecord <= LOF(5) / LocationLen Then
Get #5, LocationRecord, LocationString
If Val(Mid(LocationString, 11, 7)) > 0 Then
MsgBox ("This D11 has already been imported.")
GoTo ErrorFound
End If
End If
'Line 3 (Date Generated)
Line Input #1, TmpString
If DateValue(CurrentDate) >= DateValue(Left(Trim(TmpString), 11)) Then
MsgBox ("D11 run on same date or for a future date. Please run this again later.")
GoTo ErrorFound
End If
'Line 4 (Report Type)
Line Input #1, TmpString
If Left(Trim(TmpString), 12) <> "ALL PRODUCTS" Then
MsgBox ("Please run a Normal D11 for All Beer Products and try again.")
GoTo ErrorFound
End If
'User override
Range("B1").NumberFormat = "mmmm d, yyyy"
If MsgBox("Continue with " + Range("B1").Text, vbYesNo, "Import this D11?") = vbNo Then GoTo ErrorFound
'Identify Date and put in Starting Record #'s
ChDir ThisWorkbook.Path
Open ThisWorkbook.Path + "\" + FGDB For Random As #2 Len = FGRecLen
LocationArray(1, 0) = LOF(2) / FGRecLen + 1
FGRec = LocationArray(1, 0)
Open ThisWorkbook.Path + "\" + SKUDB For Random As #3 Len = SKURecLen
LocationArray(2, 0) = LOF(3) / SKURecLen + 1
SKURec = LocationArray(2, 0)
Open ThisWorkbook.Path + "\" + DollarDB For Random As #4 Len = DollarRecLen
LocationArray(3, 0) = LOF(4) / DollarRecLen + 1
DollarRec = LocationArray(3, 0)
RecordType = "FG"
Do Until EOF(1)
Line Input #1, TmpString
If Val(Left(Trim(TmpString), 3)) > 0 And Mid(Trim(TmpString), 3, 1) <> "-" Then
Select Case RecordType
Case "FG"
If Len(Trim(Left(TmpString, 4))) = 4 Then
CurrentName = TmpString
Else
FGString = CurrentDate + Left(CurrentName + Space(39), 39) + Left(TmpString + Space(111), 111)
Put #2, FGRec, FGString
FGRec = FGRec + 1
End If
Case "SKU"
SKUString = CurrentDate + Left(TmpString + Space(130), 130)
Put #3, SKURec, SKUString
SKURec = SKURec + 1
End Select
ElseIf Left(Trim(TmpString), 27) = "===== Package Summary =====" Then
RecordType = "SKU"
ElseIf Left(Trim(TmpString), 4) = "MEMO" Then
'I probably don't need to change the RecordType
'Most likely best to simply create the Dollar Record here
'RecordType = "DOLLAR"
TmpDollarString = CurrentDate
Range("B2").Value = Right(TmpString, 16)
Range("B2").NumberFormat = "0.00"
TmpDollarString = TmpDollarString + Left(Range("B2").Text + Space(15), 15)
Do
Line Input #1, TmpString
Loop Until Left(Trim(TmpString), 5) = "Value"
Range("B2").Value = Right(TmpString, 16)
Range("B2").NumberFormat = "0.00"
TmpDollarString = TmpDollarString + Left(Range("B2").Text + Space(15), 15)
Do
Line Input #1, TmpString
Loop Until Left(Trim(TmpString), 5) = "Value"
Range("B2").Value = Right(TmpString, 16)
Range("B2").NumberFormat = "0.00"
TmpDollarString = TmpDollarString + Left(Range("B2").Text + Space(15), 15)
DollarString = Left(TmpDollarString, DollarRecLen)
Put #4, DollarRec, DollarString
Exit Do
End If
Loop
'Identify Date and put in End Record #'s
LocationArray(1, 1) = FGRec - 1
LocationArray(2, 1) = SKURec - 1
LocationArray(3, 1) = DollarRec
LocationString = CurrentDate + Left(TS(LocationArray(1, 0)) + Space(7), 7) + Left(TS(LocationArray(1, 1)) + Space(7), 7) _
+ Left(TS(LocationArray(2, 0)) + Space(7), 7) + Left(TS(LocationArray(2, 1)) + Space(7), 7) _
+ Left(TS(LocationArray(3, 0)) + Space(7), 7) + Left(TS(LocationArray(3, 1)) + Space(7), 7)
Put #5, LocationRecord, LocationString
Close
Exit Sub
ErrorFound:
Select Case Err.Number
Case 0
Case Else
MsgBox Err.Description
End Select
Close
End Sub
[Code].