Ok, I've searched all over for an answer to fixing this dreaded E_Fail Status error I receive when trying to run a VB report against a SQL 7.0 Data Source. The report ran fine the last time I tried, and nothing has changed in the procedure. Can anyone look my code over and tell me where I could possibly be going wrong??
Public sql As New adodb.Connection
Private Sub Command1_Click()
Dim x As Integer, count As Integer, count2 As Integer, SQLP As String, SQLP2 As String, SQLS As String, rst As New adodb.Recordset, mysql As String
Dim rst2 As New adodb.Recordset, fldloop As adodb.Field, Crst As New adodb.Recordset, DateMin As Date, datmax As Date, rstDate As New adodb.Recordset
Dim ACommand As adodb.Command
Dim test As String
sql.Provider = "MSDataShape"
sql.ConnectionTimeout = 100
sql.CommandTimeout = 100
sql.Open "DSN=FreightInvoices", "sa", ""
rst.Open "Select * From tblCustomerstoSupress", sql, adOpenKeyset, adLockReadOnly
count = rst.RecordCount
x = 0
For x = 1 To count
SQLS = SQLS & "(tblFedExTrackNum.SoldTo LIKE " & "'" & rst![soldto] & "'" & ""
If x < count Then
SQLS = SQLS & " And Not "
Else: SQLS = SQLS & ""
End If
rst.MoveNext
Next x
SQLP2 = "APPEND({SELECT qryTrackingNumberCharges.TrackingNum, tbl_110_Detail_RatesAndCharges.ChargeCode, " & _
"tblFedExSpecialChargeCodes.Description, tbl_110_Detail_RatesAndCharges.ChargeAmount " & _
"FROM qryTrackingNumberCharges " & _
"LEFT OUTER JOIN tbl_110_Detail_RatesAndCharges ON qryTrackingNumberCharges.InvoiceNumber = tbl_110_Detail_RatesAndCharges.InvoiceNumber " & _
"AND qryTrackingNumberCharges.LXID = tbl_110_Detail_RatesAndCharges.LXID " & _
"LEFT OUTER JOIN tblFedExSpecialChargeCodes ON tbl_110_Detail_RatesAndCharges.ChargeCode = tblFedExSpecialChargeCodes.CodeValue " & _
"GROUP BY qryTrackingNumberCharges.TrackingNum, tbl_110_Detail_RatesAndCharges.ChargeCode, tblFedExSpecialChargeCodes.Description, " & _
"tbl_110_Detail_RatesAndCharges.ChargeAmount " & _
"ORDER BY qryTrackingNumberCharges.TrackingNum, tbl_110_Detail_RatesAndCharges.ChargeCode} RELATE TrackingNum TO TrackingNum)"
SQLP = "SHAPE{SELECT qryInvoiceFreightSums.InvoiceNum, qryInvoiceFreightSums.FedExFreight, tblFedExTrackNum.SumOffreight_xinvbox AS MunicsFreight, " & _
"qryInvoiceFreightSums.FedExFreight - tblFedExTrackNum.SumOffreight_xinvbox AS Difference, tblFedExTrackNum.shipdate_xinvbox, " & _
"tblFedExTrackNum.TrackingNum, tblFedExTrackNum.itemid_invdet, tblFedExTrackNum.SoldTo, tblNonPrePaidCust.[Customer ID] " & _
"FROM qryInvoiceFreightSums " & _
"INNER JOIN qryTrackingNumberCharges ON qryInvoiceFreightSums.TrackingNum = qryTrackingNumberCharges.TrackingNum " & _
"AND qryInvoiceFreightSums.FedExFreight = qryTrackingNumberCharges.ChargeSum " & _
"Inner Join tblFedExTrackNum ON qryInvoiceFreightSums.TrackingNum = tblFedExTrackNum.TrackingNum " & _
"LEFT OUTER JOIN tblNonPrePaidCust ON tblFedExTrackNum.SoldTo = tblNonPrePaidCust.[Customer ID] " & _
"GROUP BY qryInvoiceFreightSums.InvoiceNum, qryInvoiceFreightSums.FedExFreight, tblFedExTrackNum.SumOffreight_xinvbox, " & _
"qryInvoiceFreightSums.FedExFreight - tblFedExTrackNum.SumOffreight_xinvbox, tblFedExTrackNum.shipdate_xinvbox, " & _
"tblFedExTrackNum.TrackingNum, tblFedExTrackNum.itemid_invdet, tblFedExTrackNum.SoldTo, tblNonPrePaidCust.[Customer ID] " & _
"HAVING (qryInvoiceFreightSums.FedExFreight - tblFedExTrackNum.SumOffreight_xinvbox > 0) " & _
"AND (NOT " & SQLS & _
"AND (tblNonPrePaidCust.[Customer ID] Is Null) " & _
"ORDER BY tblFedExTrackNum.SoldTo, qryInvoiceFreightSums.InvoiceNum} AS ParentRS " & SQLP2
rst2.CursorLocation = adUseServer
rst2.Open SQLP, sql, adOpenKeyset, adLockReadOnly
rst2.ActiveConnection = Nothing
rstDate.Open "SELECT MIN(shipdate_xinvbox) AS [Min], MAX(shipdate_xinvbox) AS [Max] From tblFedExTrackNum", sql, adOpenKeyset, adLockReadOnly
DateMin = rstDate![Min]
DateMax = rstDate![Max]
Set DR.DataSource = rst2
With DR.Sections("Section2"
.Controls("lblDateRange".Caption = "For Ship Date Range " & CStr(DateMin) & " through " & CStr(DateMax) & " ."
End With
With DR.Sections("Section6"
.Controls("txtInvoiceNum".DataField = "InvoiceNum"
.Controls("txtFedExFreight".DataField = "FedExFreight"
.Controls("txtMunicsFreight".DataField = "MunicsFreight"
.Controls("txtDifference".DataField = "Difference"
.Controls("txtTrackingNum".DataField = "TrackingNum"
.Controls("txtitemid_invdet".DataField = "itemid_invdet"
.Controls("txtSoldTo".DataField = "SoldTo"
.Controls("txtshipdate_xinvbox".DataField = "shipdate_xinvbox"
End With
With DR.Sections("Section1"
.Controls("txtChargeCode".DataMember = "Chapter1"
.Controls("txtChargeCode".DataField = "ChargeCode"
.Controls("txtDescription".DataMember = "Chapter1"
.Controls("txtDescription".DataField = "Description"
.Controls("txtChargeAmount".DataMember = "Chapter1"
.Controls("txtChargeAmount".DataField = "ChargeAmount"
End With
With DR
.LeftMargin = (1440 * 0.25)
.RightMargin = (1440 * 0.25)
.TopMargin = 0
.BottomMargin = 0
End With
DR.Show
End Sub
Thanks in advance
Public sql As New adodb.Connection
Private Sub Command1_Click()
Dim x As Integer, count As Integer, count2 As Integer, SQLP As String, SQLP2 As String, SQLS As String, rst As New adodb.Recordset, mysql As String
Dim rst2 As New adodb.Recordset, fldloop As adodb.Field, Crst As New adodb.Recordset, DateMin As Date, datmax As Date, rstDate As New adodb.Recordset
Dim ACommand As adodb.Command
Dim test As String
sql.Provider = "MSDataShape"
sql.ConnectionTimeout = 100
sql.CommandTimeout = 100
sql.Open "DSN=FreightInvoices", "sa", ""
rst.Open "Select * From tblCustomerstoSupress", sql, adOpenKeyset, adLockReadOnly
count = rst.RecordCount
x = 0
For x = 1 To count
SQLS = SQLS & "(tblFedExTrackNum.SoldTo LIKE " & "'" & rst![soldto] & "'" & ""
If x < count Then
SQLS = SQLS & " And Not "
Else: SQLS = SQLS & ""
End If
rst.MoveNext
Next x
SQLP2 = "APPEND({SELECT qryTrackingNumberCharges.TrackingNum, tbl_110_Detail_RatesAndCharges.ChargeCode, " & _
"tblFedExSpecialChargeCodes.Description, tbl_110_Detail_RatesAndCharges.ChargeAmount " & _
"FROM qryTrackingNumberCharges " & _
"LEFT OUTER JOIN tbl_110_Detail_RatesAndCharges ON qryTrackingNumberCharges.InvoiceNumber = tbl_110_Detail_RatesAndCharges.InvoiceNumber " & _
"AND qryTrackingNumberCharges.LXID = tbl_110_Detail_RatesAndCharges.LXID " & _
"LEFT OUTER JOIN tblFedExSpecialChargeCodes ON tbl_110_Detail_RatesAndCharges.ChargeCode = tblFedExSpecialChargeCodes.CodeValue " & _
"GROUP BY qryTrackingNumberCharges.TrackingNum, tbl_110_Detail_RatesAndCharges.ChargeCode, tblFedExSpecialChargeCodes.Description, " & _
"tbl_110_Detail_RatesAndCharges.ChargeAmount " & _
"ORDER BY qryTrackingNumberCharges.TrackingNum, tbl_110_Detail_RatesAndCharges.ChargeCode} RELATE TrackingNum TO TrackingNum)"
SQLP = "SHAPE{SELECT qryInvoiceFreightSums.InvoiceNum, qryInvoiceFreightSums.FedExFreight, tblFedExTrackNum.SumOffreight_xinvbox AS MunicsFreight, " & _
"qryInvoiceFreightSums.FedExFreight - tblFedExTrackNum.SumOffreight_xinvbox AS Difference, tblFedExTrackNum.shipdate_xinvbox, " & _
"tblFedExTrackNum.TrackingNum, tblFedExTrackNum.itemid_invdet, tblFedExTrackNum.SoldTo, tblNonPrePaidCust.[Customer ID] " & _
"FROM qryInvoiceFreightSums " & _
"INNER JOIN qryTrackingNumberCharges ON qryInvoiceFreightSums.TrackingNum = qryTrackingNumberCharges.TrackingNum " & _
"AND qryInvoiceFreightSums.FedExFreight = qryTrackingNumberCharges.ChargeSum " & _
"Inner Join tblFedExTrackNum ON qryInvoiceFreightSums.TrackingNum = tblFedExTrackNum.TrackingNum " & _
"LEFT OUTER JOIN tblNonPrePaidCust ON tblFedExTrackNum.SoldTo = tblNonPrePaidCust.[Customer ID] " & _
"GROUP BY qryInvoiceFreightSums.InvoiceNum, qryInvoiceFreightSums.FedExFreight, tblFedExTrackNum.SumOffreight_xinvbox, " & _
"qryInvoiceFreightSums.FedExFreight - tblFedExTrackNum.SumOffreight_xinvbox, tblFedExTrackNum.shipdate_xinvbox, " & _
"tblFedExTrackNum.TrackingNum, tblFedExTrackNum.itemid_invdet, tblFedExTrackNum.SoldTo, tblNonPrePaidCust.[Customer ID] " & _
"HAVING (qryInvoiceFreightSums.FedExFreight - tblFedExTrackNum.SumOffreight_xinvbox > 0) " & _
"AND (NOT " & SQLS & _
"AND (tblNonPrePaidCust.[Customer ID] Is Null) " & _
"ORDER BY tblFedExTrackNum.SoldTo, qryInvoiceFreightSums.InvoiceNum} AS ParentRS " & SQLP2
rst2.CursorLocation = adUseServer
rst2.Open SQLP, sql, adOpenKeyset, adLockReadOnly
rst2.ActiveConnection = Nothing
rstDate.Open "SELECT MIN(shipdate_xinvbox) AS [Min], MAX(shipdate_xinvbox) AS [Max] From tblFedExTrackNum", sql, adOpenKeyset, adLockReadOnly
DateMin = rstDate![Min]
DateMax = rstDate![Max]
Set DR.DataSource = rst2
With DR.Sections("Section2"
.Controls("lblDateRange".Caption = "For Ship Date Range " & CStr(DateMin) & " through " & CStr(DateMax) & " ."
End With
With DR.Sections("Section6"
.Controls("txtInvoiceNum".DataField = "InvoiceNum"
.Controls("txtFedExFreight".DataField = "FedExFreight"
.Controls("txtMunicsFreight".DataField = "MunicsFreight"
.Controls("txtDifference".DataField = "Difference"
.Controls("txtTrackingNum".DataField = "TrackingNum"
.Controls("txtitemid_invdet".DataField = "itemid_invdet"
.Controls("txtSoldTo".DataField = "SoldTo"
.Controls("txtshipdate_xinvbox".DataField = "shipdate_xinvbox"
End With
With DR.Sections("Section1"
.Controls("txtChargeCode".DataMember = "Chapter1"
.Controls("txtChargeCode".DataField = "ChargeCode"
.Controls("txtDescription".DataMember = "Chapter1"
.Controls("txtDescription".DataField = "Description"
.Controls("txtChargeAmount".DataMember = "Chapter1"
.Controls("txtChargeAmount".DataField = "ChargeAmount"
End With
With DR
.LeftMargin = (1440 * 0.25)
.RightMargin = (1440 * 0.25)
.TopMargin = 0
.BottomMargin = 0
End With
DR.Show
End Sub
Thanks in advance