Hi,
I am new to bytes and I was hoping you could please help me with the Error - No value given for one or more parameters that occurs on the .Open MySql line of code. I m trying to extract data from a query from an access database and output this to Excel. I think there must be something wrong with the string MySql which I have used (I took most of it from the auto-generated sql code in the access query and changed the date between area to use the DateSerial fuction). I may have missed out that I need to code something else with the code...
Any help would be greatly appreciated. thank you
Alex
PS. I think it compiles correctly.
I am new to bytes and I was hoping you could please help me with the Error - No value given for one or more parameters that occurs on the .Open MySql line of code. I m trying to extract data from a query from an access database and output this to Excel. I think there must be something wrong with the string MySql which I have used (I took most of it from the auto-generated sql code in the access query and changed the date between area to use the DateSerial fuction). I may have missed out that I need to code something else with the code...
Any help would be greatly appreciated. thank you
Alex
Code:
Private Function CallHandling(ByVal x As String)
'************************************** CALL HANDLING ******************************
Dim cn As Object, rs As Object, Status As String
Dim MySql As String, dbfullname As String, myCnt As Long
dbfullname = "H:\Operations Planning\MIU\Internal\STATS\TELE\New_Call2000.mdb"
Status = "22"
'*******Q_SAGA HER BY DAY(B2B)*******
'Stack your SQL string
' SQL FOR Last 7 days DATES!
MySql = "SELECT [SumOfCalls answered]+[SumOfAbandoned] AS Offered, Sum(T_Rockwell_Application_Data.[Calls answered]) AS [SumOfCalls answered]," _
& "IIf(Sum(T_Rockwell_Application_data.[calls offered])=0,0,Sum(T_Rockwell_Application_data.[calls offered]-([calls answered]-" _
& "T_Rockwell_Application_data.[calls answered in 20 secs])-(T_Rockwell_Application_data.abandoned-T_Rockwell_Application_data.[abandoned" _
& "in 20 secs]))/Sum(T_Rockwell_Application_data.[calls offered])) AS [Svc Level], ([SumOfTotal Talk Time]+[SumOfTotal Work Time])/" _
& "[SumOfCalls answered] AS AHT, ([SumOfAbandoned]-[SumOfAbandoned in 20 Secs]) AS [Aban calls after 20 secs], Sum(T_Rockwell_Application_" _
& "Data.Abandoned) AS SumOfAbandoned, Sum(T_Rockwell_Application_Data.[Abandoned in 20 Secs]) AS [SumOfAbandoned in 20 Secs], " _
& "Sum(T_Rockwell_Application_Data.[Total Talk Time]) AS [SumOfTotal Talk Time], Sum(T_Rockwell_Application_Data.[Total Work Time]) " _
& "AS [SumOfTotal Work Time], Max(T_Rockwell_Application_Data.Date) AS MaxOfDate, Sum([Abandoned]-[abandoned in 20 secs])/[Offered] " _
& "AS [20 Sec Abd%]FROM T_Rockwell_Application_Data INNER JOIN [T_HOME ASSIST] ON (T_Rockwell_Application_Data.Application = " _
& "[T_HOME ASSIST].[Application No]) AND (T_Rockwell_Application_Data.[Application Name] = [T_HOME ASSIST].Name) AND " _
& "(T_Rockwell_Application_Data.Site = [T_HOME ASSIST].Site)WHERE ((([T_HOME ASSIST].[Sub Category])<>'Home assist engineer') AND " _
& "((T_Rockwell_Application_Data.Date) Between DateSerial(Year(Date()-7),Month(Date()-7),Day(Date()-7)) And DateSerial(Year(Date()-1),Month(Date()-1),Day(Date()-1))) " _
& "AND ((T_Rockwell_Application_Data.[Application Group])='HO' Or " _
& "(T_Rockwell_Application_Data.[Application Group]) Like 'U*') AND (([T_HOME ASSIST].[Application No])<>954 And " _
& "([T_HOME ASSIST].[Application No])<>57));"
'Clear SQL variable string
Status = Empty
Set cn = CreateObject("ADODB.Connection")
'Create DB connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbfullname & ";"
Set rs = CreateObject("ADODB.Recordset")
With rs
Set .ActiveConnection = cn
'Pass your SQL
.Source = MySql
[B].Open MySql, , 3, 1[/B] - ERROR OCCURS HERE!
myCnt = .RecordCount
If myCnt > 0 Then
.MoveLast: .MoveFirst
'Pull data to first sheet, cells a1:RecordestCountRow & column 3 3 fields in the sql pass
Windows(mstrHESWB).Activate
Sheets("CH input").Activate
Range(Cells(1, 3), Cells(myCnt + 1, 6)).CopyFromRecordset rs
End If
.Close
End With
cn.Close
Set rs = Nothing: Set cn = Nothing
End Function
Comment