andyw27
asked on
SQL Update Problem
Hi,
I have this function:
Public Function myUpdateSingleField(ByVal strField As String, ByVal strDomain As String, _
ByVal strNewField As String, Optional strCriteria As Variant)
Dim strSql As String
Dim cn As New ADODB.Connection
Set cn = New ADODB.Connection
Set cn = CurrentProject.Connection
cn.CursorLocation = adUseClient
'cn.Open
If Not IsMissing(strCriteria) Then
strSql = "UPDATE " & strDomain & " SET " & strField & " = " & strNewField & " WHERE " & strCriteria
Else
strSql = "UPDATE " & strDomain & " SET " & strField & " = " & strNewField
End If
MsgBox (strSql)
cn.Execute (strSql)
cn.Close
Set cn = Nothing
End Function
If I call with this code it works fine:
Call myUpdateSingleField("recei pt_number" , "tbl_kitting", "2222", "kitting_id = " & Forms!fdlgOutStanding.txtK itting_id. Value & " ")
However if I try to call it and change the strNewField values it fails.
strNewField = Forms!fdlgOutStanding.txtr eceipt.Val ue
Call myUpdateSingleField("recei pt_number" , "tbl_kitting", Forms!fdlgOutStanding.txtr eceipt.Val ue, "kitting_id = " & Forms!fdlgOutStanding.txtK itting_id. Value & " ")
Error: No value given for one or more required parameters.
strNewField = “test string”
Call myUpdateSingleField("recei pt_number" , "tbl_kitting", "test string", "kitting_id = " & Forms!fdlgOutStanding.txtK itting_id. Value & " ")
Error: Syntax error (missing operator) in query expression 'test string'.
Any ideas why its failing?
I have this function:
Public Function myUpdateSingleField(ByVal strField As String, ByVal strDomain As String, _
ByVal strNewField As String, Optional strCriteria As Variant)
Dim strSql As String
Dim cn As New ADODB.Connection
Set cn = New ADODB.Connection
Set cn = CurrentProject.Connection
cn.CursorLocation = adUseClient
'cn.Open
If Not IsMissing(strCriteria) Then
strSql = "UPDATE " & strDomain & " SET " & strField & " = " & strNewField & " WHERE " & strCriteria
Else
strSql = "UPDATE " & strDomain & " SET " & strField & " = " & strNewField
End If
MsgBox (strSql)
cn.Execute (strSql)
cn.Close
Set cn = Nothing
End Function
If I call with this code it works fine:
Call myUpdateSingleField("recei
However if I try to call it and change the strNewField values it fails.
strNewField = Forms!fdlgOutStanding.txtr
Call myUpdateSingleField("recei
Error: No value given for one or more required parameters.
strNewField = “test string”
Call myUpdateSingleField("recei
Error: Syntax error (missing operator) in query expression 'test string'.
Any ideas why its failing?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Perfect, thanks very much.
Andy
Open in new window