Avatar
Board Regular
- Joined
- Sep 20, 2005
- Messages
- 193
Greetings,
I can't see what i'm doing wrong here. The Update statement highlighted in red is the problem. The delete statement directly above it is my temporary workaround until i can get the update fixed.
I get the following error on the "Set Rst = Conn.Execute(MySQL)" line:
---
Run-time error '-2147217904 (80040e10)':
[Microsoft][ODBC Microsoft Access Drives] Too few parameters.
Expected 1.
---
Anyone able to lend a hand with this one? - Google’s not particularly useful on this one.
I can't see what i'm doing wrong here. The Update statement highlighted in red is the problem. The delete statement directly above it is my temporary workaround until i can get the update fixed.
Rich (BB code):
Public Const DatabasePath As String = ""
Public Const DBName As String = ""
Public Const DatabaseDIR As String = ""
Const strPassword As String = ""
Sub UploadDataTo_DB_ADO()
Dim Conn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim MySQL As String
Dim AccessConnect As String
Dim dtQueryDate As Date
dtQueryDate = Format(Sheet1.Range("Date") - (Weekday(Format(Sheet1.Range("Date"), "YYYY/MMMM/DD"), vbMonday) - 1), "YYYY/MMMM/DD")
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & DBName & ";" & _
"DefaultDir=" & DatabaseDIR & ";" & _
"Uid=Admin;Pwd=" & strPassword & ";"
Conn.Open AccessConnect
'Some dates STILL swap Month/Day around unless i put the format in the SQL line even though i've previously formatted it.
MySQL = _
"SELECT tbl_HistoricRewardScore.Date, tbl_HistoricRewardScore.Deleted " & _
"FROM tbl_HistoricRewardScore " & _
"WHERE (((tbl_HistoricRewardScore.Date)=#" & Format(dtQueryDate, "YYYY/MMMM/DD") & "#) AND ((tbl_HistoricRewardScore.Deleted)=False));"
Set Rst = Conn.Execute(MySQL)
If Not Rst.EOF Then
If MsgBox("Date already entered. Overwrite?", vbOKCancel, "Existing Record Detected") = vbOK Then
MySQL = _
"Delete tbl_HistoricRewardScore.Date " & _
"FROM tbl_HistoricRewardScore " & _
"WHERE (((tbl_HistoricRewardScore.Date)=#" & Format(dtQueryDate, "YYYY/MMMM/DD") & "#));"
'******************************************************************************'
'I can't see what i'm doing wrong here..?? Delete works, Update does not..?? '
'EDIT BY: GW '
'DATE/TIME: 16/02/2011 00:35:00 '
'******************************************************************************'
MySQL = _
"UPDATE tbl_HistoricRewardScore SET tbl_HistoricRewardScore.Deleted = True, tbl_HistoricRewardScore.DeletedBy = " & fGetUserName & ", tbl_HistoricRewardScore.DeletedDateTime = #" & Format(Now(), "YYYY/MMMM/DD HH:MM:SS") & "# " & _
"WHERE (((tbl_HistoricRewardScore.Date)=#" & Format(dtQueryDate, "YYYY/MMMM/DD") & "#) AND ((tbl_HistoricRewardScore.Deleted)=False));"
'MsgBox MySQL
'*******************************************************************************
Set Rst = Conn.Execute(MySQL)
Else
Exit Sub
End If
End If
'Is there a more efficent way of doing this?
Set Rst = New ADODB.Recordset
Rst.Open "tbl_HistoricRewardScore", Conn, adOpenKeyset, adLockOptimistic, adCmdTable
With Rst
.AddNew
!Date = Format(dtQueryDate, "YYYY/MMMM/DD") 'Date
!TransferInPercent = Sheet1.Range("TransIn") 'TransferInPercent
!TransferOutPercent = Sheet1.Range("TransOut") 'TransferOutPercent
!eISAPercent = Sheet1.Range("eISA") 'eISAPercent
!FRISAPercent = Sheet1.Range("FRISA") 'FRISAPercent
!ConsolidationPercent = Sheet1.Range("Consol") 'ConsolidationPercent
!ComplaintsStage1Percent = Sheet1.Range("Complaints") 'ComplaintsStage1Percent
!HelpdeskPercent = Sheet1.Range("HelpDesk") 'HelpdeskPercent
!QualityCheckingPercent = Sheet1.Range("Quality") 'QualityCheckingPercent
!OverallRewardPercent = Sheet1.Range("OLA") 'OverallRewardPercent
!UpdatedBy = fGetUserName 'UpdatedBy
!UpdatedDateTime = Format(Now(), "YYYY/MMMM/DD HH:MM:SS") 'UpdatedDateTime
.Update
End With
Rst.Close
Conn.Close
Set Rst = Nothing
Set Conn = Nothing
End Sub
I get the following error on the "Set Rst = Conn.Execute(MySQL)" line:
---
Run-time error '-2147217904 (80040e10)':
[Microsoft][ODBC Microsoft Access Drives] Too few parameters.
Expected 1.
---
Anyone able to lend a hand with this one? - Google’s not particularly useful on this one.