I have a buch of fields that I'd like to update on a form at once, but
I'm having a problem with allowing fields to be blank. If any of the
fields in the SQL statement are blank, the update doesn't work.
The way I see it, for example, SET ContactLastName ='' (two single
quotes) is somehow invalidating the update, although I can't seem to
find documentation on that. If this is the case, it looks like I'd
have to do some major tweaking to the code listed below. Any input
would be appreciated.
Here is the code I'm using. I had split up the SQL string assignment
because access has a limit to the number of line continuations you can
use.
Private Sub SQLUpdate()
Dim dbs As DAO.Database
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "UPDATE tblSystem " & _
"SET ContactLastName ='" & tboContactLast & "'" & _
",ContactFirstN ame='" & tboContactFirst & "'" & _
",ContactPhone= '" & tboContactPhone & "'" & _
",InstallDate=' " & tboInstallDate & "'" & _
",TimerMode l='" & tboTimerModel & "'" & _
",City='" & tboSystemCity & "'" & _
",State='" & tboSystemState & "'" & _
",Zip='" & tboSystemZip & "'" & _
",BackFlowModel ='" & tboBackFlowMode l & "'" & _
",LastActivatio n='" & tboLastActivati on & "'" & _
",LastBlowout=' " & tboLastBlowout & "'" & _
",TimerLocation ='" & tboTimerLocatio n & "'" & _
",RainSenso r='" & tboRainSensor & "'" & _
",PlumbingInsid e='" & tboPlumbingInsi de & "'" & _
",BlowOutValve= '" & tboBlowOutValve & "'" & _
",ValveBox1 ='" & tboValveBox1 & "'" & _
",ValveBox2 ='" & tboValveBox2 & "'" & _
",ValveBox3 ='" & tboValveBox3 & "'" & _
",ValveBox4 ='" & tboValveBox4 & "'" & _
",ValveBox5 ='" & tboValveBox5 & "'"
strSQL = strSQL & _
",Comments= '" & tboComments & "'" & _
" WHERE Address='" & tboSystemAddres s & "'" & _
" AND City='" & tboSystemCity & "'"
dbs.Execute (strSQL)
End Sub
I'm having a problem with allowing fields to be blank. If any of the
fields in the SQL statement are blank, the update doesn't work.
The way I see it, for example, SET ContactLastName ='' (two single
quotes) is somehow invalidating the update, although I can't seem to
find documentation on that. If this is the case, it looks like I'd
have to do some major tweaking to the code listed below. Any input
would be appreciated.
Here is the code I'm using. I had split up the SQL string assignment
because access has a limit to the number of line continuations you can
use.
Private Sub SQLUpdate()
Dim dbs As DAO.Database
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "UPDATE tblSystem " & _
"SET ContactLastName ='" & tboContactLast & "'" & _
",ContactFirstN ame='" & tboContactFirst & "'" & _
",ContactPhone= '" & tboContactPhone & "'" & _
",InstallDate=' " & tboInstallDate & "'" & _
",TimerMode l='" & tboTimerModel & "'" & _
",City='" & tboSystemCity & "'" & _
",State='" & tboSystemState & "'" & _
",Zip='" & tboSystemZip & "'" & _
",BackFlowModel ='" & tboBackFlowMode l & "'" & _
",LastActivatio n='" & tboLastActivati on & "'" & _
",LastBlowout=' " & tboLastBlowout & "'" & _
",TimerLocation ='" & tboTimerLocatio n & "'" & _
",RainSenso r='" & tboRainSensor & "'" & _
",PlumbingInsid e='" & tboPlumbingInsi de & "'" & _
",BlowOutValve= '" & tboBlowOutValve & "'" & _
",ValveBox1 ='" & tboValveBox1 & "'" & _
",ValveBox2 ='" & tboValveBox2 & "'" & _
",ValveBox3 ='" & tboValveBox3 & "'" & _
",ValveBox4 ='" & tboValveBox4 & "'" & _
",ValveBox5 ='" & tboValveBox5 & "'"
strSQL = strSQL & _
",Comments= '" & tboComments & "'" & _
" WHERE Address='" & tboSystemAddres s & "'" & _
" AND City='" & tboSystemCity & "'"
dbs.Execute (strSQL)
End Sub
Comment