Notiophilus
Registered User.
- Local time
- Today, 15:54
- Joined
- Jan 18, 2015
- Messages
- 42
ETA: IGNORE EVERYTHING, I'M AN IDIOT
I have some filter controls on my form whose values I save to a bookmarks table on Form_Unload. I save them if and only if the control value (stored in .Tag) <> the default value. Some default values are null, e.g. triple-state checkboxes, so I stuck a Nz on it:
To my surprise, though, Nz(ctl.DefaultValue) returns Null.
It's not really an issue - I can work around it by making a special case for the one control where DefaultValue actually matters, or just store the DefaultValues to ctl.Tag - but I'd still like to know why Nz() doesn't work as expected here.
Full code in case it's relevant:
I have some filter controls on my form whose values I save to a bookmarks table on Form_Unload. I save them if and only if the control value (stored in .Tag) <> the default value. Some default values are null, e.g. triple-state checkboxes, so I stuck a Nz on it:
If ctl.Tag <> Nz(ctl.DefaultValue) Then do stuff
To my surprise, though, Nz(ctl.DefaultValue) returns Null.
It's not really an issue - I can work around it by making a special case for the one control where DefaultValue actually matters, or just store the DefaultValues to ctl.Tag - but I'd still like to know why Nz() doesn't work as expected here.
Full code in case it's relevant:
Private Sub cmdFilterOn_Click(): ctl.Tag = ctl.Value
Code:
'Save the last used filter values to bookmarks (control1.name ¬ control1.value | control2.name...). Do not save nulls.
strStoredControls = ""
For Each ctl In Me.Form.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
If ctl.Tag <> Nz(ctl.DefaultValue) Then 'HERE IS THE PROBLEM
strStoredControls = strStoredControls & ctl.Name & "¬" & ctl.Tag & "|"
End If
End If
Next
lngLen = Len(strStoredControls)
If lngLen > 0 Then strStoredControls = Left(strStoredControls, lngLen - 1)
strSQL2 = "UPDATE [luBookmark] " & _
"SET [Data] = """ & strStoredControls & """" & _
" WHERE [BookmarkID] = 2"
DBEngine(0)(0).Execute strSQL2, dbFailOnError
Last edited: