C
Chace
I have a weird problem:
I get a connection run-time error if I try to open the third recordset in
the procedure below. Does anyone know what the problem might be?
Private Sub cmd_Update_Click()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim MySQL As String
Dim dtStart As Date
Dim dtEnd As Date
Dim strMonth As String
Set rs = New ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=K:\Channelview 2\Adage queries\RawMaterial Adage
TableQuery.mdb"
For i = 5 To 17
If ActiveSheet.Cells(3, i) = 1 Then
dtStart = ActiveSheet.Cells(1, i)
dtEnd = ActiveSheet.Cells(2, i)
strMonth = ActiveSheet.Cells(4, i)
'Calculate fresh production
MySQL = "SELECT Sum([qsel_SMA Production3].[Fresh Production]) " & _
"AS [SumOfFresh Production] " & _
"FROM [qsel_SMA Production3] " & _
"WHERE ((([qsel_SMA Production3].Date1) Between #" & dtStart & "# "
& _
"and #" & dtEnd & "#" & _
"));"
rs.Open MySQL, cnn
Dim dblFreshProduction As Double
dblFreshProduction = Nz(rs![sumofFresh Production], 0)
ActiveSheet.Range(strMonth & "ProductionLBSSMA").Value =
Format(Nz(dblFreshProduction, 0), "##,###,##0")
rs.Close
dtStart = ActiveSheet.Cells(1, i)
dtEnd = ActiveSheet.Cells(2, i)
strMonth = ActiveSheet.Cells(4, i)
'Calculate Inventory
MySQL = "SELECT Sum([SMA qry no SDWuser].LBS) AS SumOfLBS " & _
"FROM [SMA qry no SDWuser];"
rs.Open MySQL, cnn
Dim dblSMAInventory As Double
dblSMAInventory = Nz(rs![sumofLBS], 0)
ActiveSheet.Range(strMonth & "InventorySMA").Value =
Format(Nz(dblSMAInventory, 0), "##,###,##0")
rs.Close
'Calculate % Off Spec
MySQL = "SELECT Sum([SMA qry].LBS) AS SumOfLBS FROM [SMA qry] " & _
"WHERE ((([SMA qry].[Lot Status]) Like 'z*' " & _
"Or ([SMA qry].[Lot Status]) Like 'D-OffSpcRl'));"
'************************************
'The next line is where I get the run-time error -2147467259 (80004005)
'************************************
rs.Open MySQL, cnn
Dim dblSMApercentOffSpec As Double
dblSMApercentOffSpec = (Nz(rs![sumofLBS], 0) + 0.0001) /
dblSMAInventory
ActiveSheet.Range(strMonth & "OSpercentSMA").Value =
Format(Nz(dblSMApercentOffSpec, 0), "##0%")
rs.Close
End If
Next i
Set rs = Nothing
cnn.Close
Set cnn = Nothing
End Sub
I get a connection run-time error if I try to open the third recordset in
the procedure below. Does anyone know what the problem might be?
Private Sub cmd_Update_Click()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim MySQL As String
Dim dtStart As Date
Dim dtEnd As Date
Dim strMonth As String
Set rs = New ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=K:\Channelview 2\Adage queries\RawMaterial Adage
TableQuery.mdb"
For i = 5 To 17
If ActiveSheet.Cells(3, i) = 1 Then
dtStart = ActiveSheet.Cells(1, i)
dtEnd = ActiveSheet.Cells(2, i)
strMonth = ActiveSheet.Cells(4, i)
'Calculate fresh production
MySQL = "SELECT Sum([qsel_SMA Production3].[Fresh Production]) " & _
"AS [SumOfFresh Production] " & _
"FROM [qsel_SMA Production3] " & _
"WHERE ((([qsel_SMA Production3].Date1) Between #" & dtStart & "# "
& _
"and #" & dtEnd & "#" & _
"));"
rs.Open MySQL, cnn
Dim dblFreshProduction As Double
dblFreshProduction = Nz(rs![sumofFresh Production], 0)
ActiveSheet.Range(strMonth & "ProductionLBSSMA").Value =
Format(Nz(dblFreshProduction, 0), "##,###,##0")
rs.Close
dtStart = ActiveSheet.Cells(1, i)
dtEnd = ActiveSheet.Cells(2, i)
strMonth = ActiveSheet.Cells(4, i)
'Calculate Inventory
MySQL = "SELECT Sum([SMA qry no SDWuser].LBS) AS SumOfLBS " & _
"FROM [SMA qry no SDWuser];"
rs.Open MySQL, cnn
Dim dblSMAInventory As Double
dblSMAInventory = Nz(rs![sumofLBS], 0)
ActiveSheet.Range(strMonth & "InventorySMA").Value =
Format(Nz(dblSMAInventory, 0), "##,###,##0")
rs.Close
'Calculate % Off Spec
MySQL = "SELECT Sum([SMA qry].LBS) AS SumOfLBS FROM [SMA qry] " & _
"WHERE ((([SMA qry].[Lot Status]) Like 'z*' " & _
"Or ([SMA qry].[Lot Status]) Like 'D-OffSpcRl'));"
'************************************
'The next line is where I get the run-time error -2147467259 (80004005)
'************************************
rs.Open MySQL, cnn
Dim dblSMApercentOffSpec As Double
dblSMApercentOffSpec = (Nz(rs![sumofLBS], 0) + 0.0001) /
dblSMAInventory
ActiveSheet.Range(strMonth & "OSpercentSMA").Value =
Format(Nz(dblSMApercentOffSpec, 0), "##0%")
rs.Close
End If
Next i
Set rs = Nothing
cnn.Close
Set cnn = Nothing
End Sub