Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DarkSide of the Null

Status
Not open for further replies.

Kherozen

Programmer
Jun 5, 2003
129
CA
Hi,
ok can someone explain me what I am doing wrong :

I got some code to Clear all the Field of a form with subforms
and it goes like that(Btw if there's a easiest/simple way tell me, i'm quite new to vba/access)

Code:
For Each myControl In Controls
    Select Case myControl.ControlType
        Case acTextBox, acComboBox, acCheckBox
              myControl.Value = ""
        Case acSubform
            For Each mySubControl In myControl.Form.Controls
                Select Case mySubControl.ControlType
                    Case acTextBox, acComboBox
                        mySubControl.Value = ""
                End Select
            Next
            
    End Select
Next

now the thing is after I pressed the button that do that ... I do (in another button) a check of the lenght of each acTextbox/acCombobox and the weird things begin : for myControl everything is fine [tt]len(myControl.value)[/tt] returns 0 but weirdly for mysubControl, [tt]len(mySubControl.Value)[/tt] returns 4 I suppose for 'NULL' ... any idea why?!?! (and I need it to return 0! btw I looked into the Debug and put a watch on mySubControl.Value and it's equal to "" but still return 4 as lenght...)

btw i'm using Access 2000 with SQL Server 2000



jul ^_^
"Computer Science is no more about computers than astronomy is about telescopes"
E. W. Dijkstra.
 
dialing in from the road without benefit of my vast reference library but you need the null to zero function where a null is changed into a zero...makes sense, doesn't it?

Look in the access help file and/or try this:

For Each myControl In Controls
Select Case myControl.ControlType
Case acTextBox, acComboBox, acCheckBox
[red]myControl.Value = (Nz(""))[/red]
Case acSubform
For Each mySubControl In myControl.Form.Controls
Select Case mySubControl.ControlType
Case acTextBox, acComboBox
[red]mySubControl.Value = (Nz(""))[/red]
End Select
Next

End Select
Next



Judge Hopkins


There are only two rules for success: (1) Never tell everything you know.
 
Thanks, but that wasn't the problem.

and I just find it ...

just to look more stupid that I usually do ... here's my mistake
[tt]
..
...
if len(myControl.value) > 0 then ...
...
if len(mySubControl.value >0) then ...[/tt]
which return 4 because of 'TRUE' not 'NULL' .... (well actualy it return 5 but if 5 then ... it's true so I that's why I saw 4 ...)



jul ^_^
"Computer Science is no more about computers than astronomy is about telescopes"
E. W. Dijkstra.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top