SQL UPDATE String Issue

CharlesWhiteman

Registered User.
Local time
Today, 22:04
Joined
Feb 26, 2007
Messages
421
I have the following code and have highlighted the issue part in red. Basically the code works but when using the highlighted string I get a data type mismatch error. If I replace the string with a reference to the txt box then Access pops up and asks for the ID at which point if i enter it then it works fine.

'Update Address Details To Primary Data
Dim varPK As String
varPK = Me.txtPrimaryDataID
Dim strSQLUpdate As String
Dim varAddress1 As String
varAddress1 = Me.txtAddress1
Dim varAddress2 As String
varAddress2 = Me.txtAddress2
Dim VarCity As String
VarCity = Me.txtCity
Dim varCounty As String
varCounty = Me.txtCounty
Dim varPostCode As String
varPostCode = Me.txtPostCode
strSQLUpdate = "UPDATE tblPrimaryData SET Address1 = '" & [varAddress1] & "', Address2 = '" & [varAddress2] & "',City = '" & [VarCity] & "', County = '" & [varCounty] & "', PostCode = '" & [varPostCode] & "' WHERE PrimaryDataID = '" & [varPK] & "';"
'DoCmd.RunSQL strSQLUpdate
 
I fixed it by removing quotes

WHERE PrimaryDataID = " & [varPK] & ";"

I was about to ask you if the PrimaryDataID was a Number or a String, since you were comparing PrimaryDataID to a String value (due to the quotes). Sometimes something as small as a single quote ' can cause so much grief!

Congratulations on figuring it out on your own.
 

Users who are viewing this thread

Back
Top Bottom