How to post Blank Form Fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with with about 35 controls on the form. The datatype of the
forms are Text type, Date type and Number type.

Now while posting data, the user does get all the information so he only
able to post some of the control and many of them are blank.

I want to post the value to the blank fields as follows, the below codes I
have just written to make better understand my need, I know its not correct..

I want to run the Code just before it moves to next record:

Dim ctl as Control
For Each ctl In Forms(ActiveForm).Controls
If ctl.DataType = Text And Is Null Then
ctl.value = "No Info"
ElseIf ctl.DataType = Number And Is Null Then
ctl.value = 0
ElseIf ctl.DataType = Date And Is Null Then
ctl.value = Now()
End If
Next


Requesting the Professionals to kindly correct my above code, so that I can
complete this code to use it.

Regards.

Irshad.
 
While this may work, a few thoughts...

1) You can use the "default" to do some of this.

2) If you fill stuff in, what will prompt the person to go back and get the
data later? In other words, how will you know that they left the data blank
if you fill it in for them? Why not just leave it blank?

3) If you are concerned with this printing on reports, queries, or other
forms, DON'T store these place fillers in the table; leave the table blank.
Instead, code your reports to display other values in place of the NULLs.
This is the normal way to handle this. There is even a handy built in
function that lets you replace a Null value with something else. For
example...

= Nz([SomeFieldName],"No data")

That will EITHER print the value of [SomeFieldName] unless it is blank, then
it will print "No data".


I would encourage you to rethink this and use more "normal" options.

Just my opinion
 
You need to specify what you are checking on each side of the And statement.

Example:
If ctl.DataType = Text And IsNull(ctl) Then

Also, to check the Data Type, use the functions IsNumeric() and IsDate().
Assume everything else to be text. By "posting" do you mean storing the
value in the table? If so, then I wouldn't do this for the text fields, I
would store the Null instead of the "No Info". You could have Null display
as "No Info" in the control if you wanted. To do this, set the Format
property of the control to

@;"No Info"

For the date and number fields, you may just want to set their Default Value
properties to Now() and 0. Be aware that Now() will return date and time, if
all you want is the date, use Date(). However, this wouldn't prevent the
user from erasing the default value, so you would still need to do your
check. You could also use the Format property of these controls to change
the display.
 
Back
Top