phendrena
04-01-2009, 07:19 AM
Hi There,
I have the following code in an excel workbook that doesn't work - I get an error 'Data Type mismatch in criteria expression'.
Private Sub UpdateData()
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oConn As Object
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary
On Error GoTo ErrHandler
sConnect = glob_sConnect
sSQL = "SELECT * From [ExtranetDetails]"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText
' Check to make sure we received data.
If oRS.EOF Then
MsgBox "No records returned.", vbCritical
Else
sSQL = "UPDATE [ExtranetDetails] " & _
"SET [ExtranetDetails].Comments = '" & Me.txtComments.Value & "' " & _
"WHERE [ExtranetDetails].UniqueID = '" & Me.txtUniqueID.Value & "' AND [ExtranetDetails].RecordID = '" & Me.txtRecordID.Value & "'"
' MsgBox sSQL
oRS.ActiveConnection.Execute sSQL
sSQL = "SELECT * From [ExtranetDetails]"
oRS.ActiveConnection.Execute sSQL
ary = oRS.GetRows
'MsgBox ary(0, 0) & " " & ary(1, 0) & ", " & ary(2, 0)
MsgBox "Record Updated", vbInformation
End If
oRS.Close
Set oRS = Nothing
Exit Sub
ErrHandler:
MsgBox "Error : " & Err.Description & " " & sSQL, vbExclamation
End Sub
As far as I can see there are no errors with the code and there shouldn't be anything wrong with the Access datatable as ALL fields, with the exception of the autonumber are TEXT fields. None of the fields within the excel userform are formatted in any specific way.
The only field that I am trying to update if the comments field, this is limited to 250 characters with the excel workbook and also the access database.
Would anyone be able to provide any suggestions?
As a side note, a version of above code does work when it references a different datatable/workbook.
Private Sub UpdateData
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oConn As Object
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary
On Error GoTo ErrHandler
sConnect = glob_sConnect
sSQL = "SELECT * From 7DaySupport"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText
' Check to make sure we received data.
If oRS.EOF Then
MsgBox "No records returned.", vbCritical
Else
sSQL = "UPDATE [7DaySupport] " & _
"SET [7DaySupport].[7DayTeamActioned] = '" & Me.cboActioned.Value & "' " & _
"WHERE [7DaySupport].[CustomerManager] = '" & Me.txtCM.Value & "' AND [7DaySupport].[PolicyRegNo] = '" & Me.txtPolReg.Value & "'"
oRS.ActiveConnection.Execute sSQL
sSQL = "SELECT * From [7DaySupport]"
oRS.ActiveConnection.Execute sSQL
ary = oRS.GetRows
'MsgBox ary(0, 0) & " " & ary(1, 0) & ", " & ary(2, 0)
MsgBox "Record Updated", vbInformation
End If
oRS.Close
Set oRS = Nothing
Exit Sub
ErrHandler:
MsgBox "ERROR : " & sSQL, vbCritical
End Sub
Thanks,
I have the following code in an excel workbook that doesn't work - I get an error 'Data Type mismatch in criteria expression'.
Private Sub UpdateData()
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oConn As Object
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary
On Error GoTo ErrHandler
sConnect = glob_sConnect
sSQL = "SELECT * From [ExtranetDetails]"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText
' Check to make sure we received data.
If oRS.EOF Then
MsgBox "No records returned.", vbCritical
Else
sSQL = "UPDATE [ExtranetDetails] " & _
"SET [ExtranetDetails].Comments = '" & Me.txtComments.Value & "' " & _
"WHERE [ExtranetDetails].UniqueID = '" & Me.txtUniqueID.Value & "' AND [ExtranetDetails].RecordID = '" & Me.txtRecordID.Value & "'"
' MsgBox sSQL
oRS.ActiveConnection.Execute sSQL
sSQL = "SELECT * From [ExtranetDetails]"
oRS.ActiveConnection.Execute sSQL
ary = oRS.GetRows
'MsgBox ary(0, 0) & " " & ary(1, 0) & ", " & ary(2, 0)
MsgBox "Record Updated", vbInformation
End If
oRS.Close
Set oRS = Nothing
Exit Sub
ErrHandler:
MsgBox "Error : " & Err.Description & " " & sSQL, vbExclamation
End Sub
As far as I can see there are no errors with the code and there shouldn't be anything wrong with the Access datatable as ALL fields, with the exception of the autonumber are TEXT fields. None of the fields within the excel userform are formatted in any specific way.
The only field that I am trying to update if the comments field, this is limited to 250 characters with the excel workbook and also the access database.
Would anyone be able to provide any suggestions?
As a side note, a version of above code does work when it references a different datatable/workbook.
Private Sub UpdateData
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oConn As Object
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary
On Error GoTo ErrHandler
sConnect = glob_sConnect
sSQL = "SELECT * From 7DaySupport"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText
' Check to make sure we received data.
If oRS.EOF Then
MsgBox "No records returned.", vbCritical
Else
sSQL = "UPDATE [7DaySupport] " & _
"SET [7DaySupport].[7DayTeamActioned] = '" & Me.cboActioned.Value & "' " & _
"WHERE [7DaySupport].[CustomerManager] = '" & Me.txtCM.Value & "' AND [7DaySupport].[PolicyRegNo] = '" & Me.txtPolReg.Value & "'"
oRS.ActiveConnection.Execute sSQL
sSQL = "SELECT * From [7DaySupport]"
oRS.ActiveConnection.Execute sSQL
ary = oRS.GetRows
'MsgBox ary(0, 0) & " " & ary(1, 0) & ", " & ary(2, 0)
MsgBox "Record Updated", vbInformation
End If
oRS.Close
Set oRS = Nothing
Exit Sub
ErrHandler:
MsgBox "ERROR : " & sSQL, vbCritical
End Sub
Thanks,