I have an Excel file that errors with the following Visual Basic error message:
Run-time error '-2147217900 (80040e14)':
[Microsoft][ODBC SQL SERVER DRIVER][SQL SERVER]Invalid column name 'P1424'.
The debug code excerpt is shown below. The last line in the code excerpt is highlighted when I click the error message's debug button. Is this error message telling me that the SQL db has an incorrect column name? This Excel file also utilizes Access dbs, but the error reads to me that the issue is with the SQl db, and not Access. Am I correct, or how do I verify this?
Thanks
Run-time error '-2147217900 (80040e14)':
[Microsoft][ODBC SQL SERVER DRIVER][SQL SERVER]Invalid column name 'P1424'.
The debug code excerpt is shown below. The last line in the code excerpt is highlighted when I click the error message's debug button. Is this error message telling me that the SQL db has an incorrect column name? This Excel file also utilizes Access dbs, but the error reads to me that the issue is with the SQl db, and not Access. Am I correct, or how do I verify this?
Thanks
Code:
'################## THIS MODULE HAS BEEN UPDATED TO NEW SQL DATABASE #########################
Dim DBD As DAO.Database
Dim wr As Integer
Sub Test_C050R()
Run_C050R 7, 1, 8, 5, "088", "NNNNYYY", False, "01/05/2015"
End Sub
Sub Run_C050R(tType, sType, Rspec, SOlevel, SOLevelVal, SOsubs, SOoutline, Optional weekEnd)
'everything is now stype=1
Dim anaRow As Integer, dmmRow As Integer, buyRow As Integer, cpsRow As Integer
Dim DBI As DAO.Database
Dim RSA As DAO.Recordset, RSD As DAO.Recordset
Dim RSDCV As New ADODB.Recordset
Dim RANA As DAO.Recordset, RDMM As DAO.Recordset, RBUY As DAO.Recordset
Select Case SOlevel
Case 1
xWhere = ""
Case 2
xWhere = "Rspec = '" & SOLevelVal & "'"
Case 3
xWhere = "DMM = '" & SOLevelVal & "'"
Case 4
xWhere = "Buyer = '" & SOLevelVal & "'"
Case 5
xWhere = "Dept = '" & SOLevelVal & "'"
Case 6
xWhere = "Dept = '" & Mid(SOLevelVal, 1, 3) & "'"
Case 7
xWhere = "Dept = '" & Mid(SOLevelVal, 1, 3) & "'"
Case Else
msg = "Report failed - Invalid SOLevel Value"
GoTo Abort_C050R
End Select
CnRP.Open "DRIVER={SQL SERVER};SERVER=M598-repldb-1.internal.bntn.com;DATABASE=replenishment", "Repluser", "R3plu53r"
storeGroup = "Total Company"
'prep a blank workbook
Application.Workbooks.Add xlWorksheet
Set WBR = Application.ActiveWorkbook
Set WSR = WBR.ActiveSheet
Application.Calculation = xlCalculationManual
Application.ActiveWindow.Zoom = 75
wr = 1
cArray = Array(0, 0, 35, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8)
tArray = Array("", "", "", "Curr Model Units", "Curr Onhand Units", "Curr SKULoc", "Curr StkOuts", "Avg Mdl/Sku Loc", "LW", _
"WK2", "WK3", "WK4", "WK5", "12w Avg", _
"26w Avg")
For n = 0 To 14
WSR.Cells(1, n + 1).ColumnWidth = cArray(n)
WSR.Cells(4, n + 1) = tArray(n)
Next n
With WSR.Range(WSR.Cells(4, 1), WSR.Cells(4, 26))
.WrapText = True
.HorizontalAlignment = xlHAlignCenter
End With
Set DBI = OpenDatabase(DB_IMG1)
Set RSD = DBI.OpenRecordset("SELECT * FROM CntlWeek", dbOpenDynaset)
'Get the time span
If tType = 6 Then
xFromDate = Date - 182
xToDate = Date
ElseIf tType = 7 Then
xToDate = CDate(weekEnd)
xFromDate = xToDate - 175
Else
msg = "Report failed - Invalid timespan"
GoTo Abort_C050R
End If
Do Until RSD!EOWDate > xFromDate - 1
RSD.MoveNext
Loop
wc = 3
xPref = "+P"
span1 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
RSD.MoveNext
For fld = 1 To 13
span1 = span1 & xPref & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
RSD.MoveNext
Next fld
span2 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
RSD.MoveNext
For fld = 15 To 25
Select Case fld
Case 21
Wk5 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
Case 22
Wk4 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
Case 23
Wk3 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
Case 24
Wk2 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
Case 25
Wk1 = "P" & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
rTitle = storeGroup & " Replenishment Stock Out Analysis (for week ending " & RSD!EOWDate & ")"
With WSR.Cells(1, 1): .Value = rTitle: .Font.Size = 14: .Font.FontStyle = "Bold": End With
End Select
span2 = span2 & xPref & Mid(RSD!YrWkNum, 3, 2) & Mid(RSD!YrWkNum, 5, 2)
RSD.MoveNext
Next fld
RSD.Close: Set RSD = Nothing
span1 = span1 & "+" & span2
Set RANA = DBI.OpenRecordset("Repl_Spec", dbOpenDynaset)
Set RDMM = DBI.OpenRecordset("DMM", dbOpenDynaset)
Set RBUY = DBI.OpenRecordset("Buyer Table", dbOpenDynaset)
wr = 5
cpsRow = 0: anaRow = 0: dmmRow = 0: buyRow = 0
cpsInd = 0: anaInd = 0: dmmInd = 0: buyInd = 0: depInd = 0
maxInd = 0
If SOlevel = 1 Then
cpsRow = wr: wr = wr + 2
If Mid(SOsubs, 2, 1) = "Y" Then anaRow = wr: wr = wr + 1: anaInd = maxInd: maxInd = maxInd + 1
If Mid(SOsubs, 3, 1) = "Y" Then dmmRow = wr: wr = wr + 1: dmmInd = maxInd: maxInd = maxInd + 1
If Mid(SOsubs, 4, 1) = "Y" Then buyRow = wr: wr = wr + 1: buyInd = maxInd: maxInd = maxInd + 1
depInd = maxInd: maxInd = maxInd + 1
ElseIf SOlevel = 2 Then
anaRow = wr: wr = wr + 2
If Mid(SOsubs, 3, 1) = "Y" Then dmmRow = wr: wr = wr + 1: dmmInd = maxInd: maxInd = maxInd + 1
If Mid(SOsubs, 4, 1) = "Y" Then buyRow = wr: wr = wr + 1: buyInd = maxInd: maxInd = maxInd + 1
'dmmRow = wr: wr = wr + 1: dmmInd = maxInd: maxInd = maxInd + 1
'buyRow = wr: wr = wr + 1: buyInd = maxInd: maxInd = maxInd + 1
depInd = maxInd: maxInd = maxInd + 1
ElseIf SOlevel = 3 Then
dmmRow = wr: wr = wr + 2
If Mid(SOsubs, 4, 1) = "Y" Then buyRow = wr: wr = wr + 1: buyInd = maxInd: maxInd = maxInd + 1
depInd = maxInd: maxInd = maxInd + 1
ElseIf SOlevel = 4 Then
buyRow = wr: wr = wr + 2
depInd = maxInd: maxInd = maxInd + 1
Else
End If
If xWhere = "" Then
xWhere = "[Dept Table].Rspec Not Like '99' "
Else
xWhere = "((" & xWhere & ") AND ([Dept Table].Rspec Not Like '99')) "
End If
SQLA = "SELECT [Dept Table].Rspec, [Dept Table].DMM, [Dept Table].Buyer, [Dept Table].Dept, [Dept Table].DeptName " & _
"FROM [Dept Table] " & _
"WHERE " & xWhere & _
"ORDER BY [Dept Table].Rspec, [Dept Table].DMM,[Dept Table].Buyer, [Dept Table].Dept"
Set RSA = DBI.OpenRecordset(SQLA, dbOpenDynaset)
If Not RSA.RecordCount > 0 Then Application.Calculation = xlCalculationAutomatic: Exit Sub
currAna = RSA!Rspec
currDmm = RSA!DMM
currBuy = RSA!Buyer
Do Until RSA.EOF
With WSR.Cells(wr, 3)
.Value = "Dept: " & RSA!dept & " " & RSA!DeptName
.IndentLevel = depInd
End With
WSR.Cells(wr, 2) = 1
'get dept stock outs
SQL1 = "SELECT dbo.DCVWeek.Dept, dbo.DCVWeek.Ele, SUM(" & span1 & ") AS Span1, Sum(" & span2 & ") AS Span2, SUM(" & _
Wk1 & ") AS WK1, Sum(" & Wk2 & ") AS Wk2, Sum(" & Wk3 & ") AS Wk3, Sum(" & Wk4 & ") AS Wk4, SUM(" & Wk5 & ") AS Wk5 " & _
"FROM dbo.DCVWeek " & _
"GROUP BY dbo.DCVWeek.Dept, dbo.DCVWeek.Ele " & _
"HAVING (dbo.DCVWeek.Dept=" & Val(RSA!dept) & ")"
RSDCV.CursorLocation = adUseClient
RSDCV.Open SQL1, CnRP, adOpenStatic, adLockReadOnly, adCmdText