How can I set a default value to null?

L

Laurel

In the script below I get an error "type mismatch" when the 2nd statement is
executed. In some situations I want the Academics field for a new row to be
null, and in others I want it to be 5. How can I set the DefaultValue to
null?

'Initialize the Academic score
If cboPeriod_Code = "B"
Forms!frmScoreEntry!Academics = Null
Forms!frmScoreEntry!Academics.DefaultValue = Null
Else
Forms!frmScoreEntry!Academics = 5
Forms!frmScoreEntry!Academics.DefaultValue = 5
End If
 
R

Rick Brandt

Laurel said:
In the script below I get an error "type mismatch" when the 2nd statement is
executed. In some situations I want the Academics field for a new row to be
null, and in others I want it to be 5. How can I set the DefaultValue to
null?

'Initialize the Academic score
If cboPeriod_Code = "B"
Forms!frmScoreEntry!Academics = Null
Forms!frmScoreEntry!Academics.DefaultValue = Null
Else
Forms!frmScoreEntry!Academics = 5
Forms!frmScoreEntry!Academics.DefaultValue = 5
End If

A DefaultValue of Null is really just the same as not having DefaultValue at all
so try setting the property to a zero-length-string instead.

'Initialize the Academic score
If cboPeriod_Code = "B"
Forms!frmScoreEntry!Academics = Null
Forms!frmScoreEntry!Academics.DefaultValue = ""
Else
Forms!frmScoreEntry!Academics = 5
Forms!frmScoreEntry!Academics.DefaultValue = 5
End If
 
P

Philip

Something else I just noticed. Looks like you can set a value to nuthing.
a = Nuthing.
I use nuthing with Recordsets etc to free up the resorces, looks like it
also sets the value back to Null
.... Just a thought.
 
V

Van T. Dinh

In addition to what Rick wrote, note that the DefaultValue is a Text-type
Property so if you want to set the DefaultValue, you should assign it a Text
value (Null is NOT a Text value). The properly-typed syntax for the
corresponding statement in the Else part is:

Forms!frmScoreEntry!Academics.DefaultValue = "5"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top