'**********************************************************
'build a sql statement to update all of the columns to null
'**********************************************************
strSQL = "UPDATE " & Me.RecordSource & " SET "
'*************************************************************************************************
'spin through all of the active record columns and set the Columns clause
and Where clause critera
'*************************************************************************************************
For index = 0 To Me.Recordset.fields.Count - 1
strSQLCols = strSQLCols & "[" & Me.Recordset.fields(index).name & "]
" & " = NULL" & ","
'***********************************************
'enclose the field value in quotes if applicable
'***********************************************
If Len(Trim(Me.Recordset.fields(index))) > 0 Then
Select Case Me.Recordset.fields(index).name
Case "SR Num", "Tracker Item"
strSQLWhere = strSQLWhere & "[" & Me.Recordset.fields
(index).name & "]" & "=" & Me.Recordset.fields(index).Value & " AND "
Case Else
strSQLWhere = strSQLWhere & "[" & Me.Recordset.fields
(index).name & "]" & "='" & Me.Recordset.fields(index).Value & "' AND "
End Select
End If
Next index
'**********************************************************************
'remove the trailing comma delimiters from the columns and where clause
'**********************************************************************
If Right(strSQLCols, 1) = "," Then strSQLCols = Left(strSQLCols, Len
(strSQLCols) - 1)
If Right(strSQLWhere, 5) = " AND " Then strSQLWhere = Left(strSQLWhere,
Len(strSQLWhere) - 5)
'***********************************
'build the update SQL and execute it
'***********************************
If Len(strSQLWhere) > 0 Then
strSQL = strSQL & strSQLCols & " WHERE " & strSQLWhere
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
cmbSRNum.Requery
cmbSRNum = Null
End If
'****************
'refresh the form
'****************
Me.Refresh
Exit_Command37_Click:
Exit Sub
Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click
End Sub