Currently, I am trying to write code to programmatically convert null values into non-nulls for various data types. In the present method, I have to name each field individually and recode using a sql statement.
Ideally, I would like to programmatically cycle through the recordset and convert all null dates to a standard value, all the null numeric values to another standard, and all the null strings to yet another standard.
How do I accomplish the null conversion via a vba method?
Ideally, I would like to programmatically cycle through the recordset and convert all null dates to a standard value, all the null numeric values to another standard, and all the null strings to yet another standard.
How do I accomplish the null conversion via a vba method?
Code:
‘*PRESENT METHOD **********************************************
‘
strSQL_qun_ABC_RecodeNULLs = "SELECT " _
& "IIf(IsNull([lngFIELD1]),0,[lngFIELD1]) AS lngFIELD1r," _
& "IIf(IsNull([lngFIELD2]),0,[lngFIELD2]) AS lngFIELD2r," _
& "IIf(IsNull([strFIELD3]),' ',[strFIELD3]) AS strFIELD3r," _
& "IIf(IsNull([strFIELD4]),' ',[strFIELD4]) AS strFIELD4r," _
& "IIf(IsNull([strFIELD5]),' ',[strFIELD5]) AS strFIELD5r," _
& "IIf(IsNull([shortFIELD6]),0,[shortFIELD6]) AS shortFIELD6r," _
& "IIf(IsNull([strFIELD7]),' ',[strFIELD7]) AS strFIELD7r," _
& "IIf(IsNull([strFIELD8]),' ',[strFIELD8]) AS strFIELD8r," _
& "IIf(IsNull([strFIELD9]),' ',[strFIELD9]) AS strFIELD9r," _
& "IIf(IsNull([dteFIELD10]),#12/12/12#,[dteFIELD10]) AS dteFIELD10r," _
& "IIf(IsNull([dteFIELD11]),#12/12/12#,[dteFIELD11]) AS dteFIELD11r," _
& "FROM qun_ABC;"
‘*IDEAL METHOD'*********************************
'Types "10" = String / "4" = Long / "7" = Double / "8" = Date/Time
Set db = CurrentDb
Set rst = db.OpenRecordset("tbl_qun_ABC", dbOpenTable)
If rst.RecordCount = 0 Then
GoTo MyExit
Else
rst.MoveFirst
End If
Do Until rst.EOF
If fld.Type = "10" And fld = Null Then fld = " "
If fld.Type = "4" And fld = Null Then fld = 0
If fld.Type = "7" And fld = Null Then fld = 0
If fld.Type = "8" And fld = Null Then fld = #12/12/12#
End If
rst.MoveNext
Loop
'**********************************