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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why doesn't VBA read this? (Access) 1

Status
Not open for further replies.

AxeaXeaxE

Programmer
Apr 22, 2002
21
NL
I wrote some procedures which are like the following:

If KzeDag.Value = Null Then
dag = "**"
Else: dag = KzeDag.Value
Stop
End If

If the procedure has stopped, it says KzeDag.value = Null, but he doesn't proceed with the action dag = "**", instead he jumps to the else-action.
KzeDag is a list of values. I've had and still have problems with VBA reading whether the field is empty or not. What's the explanation for this and can anyone tell me how to solve it?
 
What is KzeDag? Is it a control? If it is a control, did you try the .Selected property?

If it is an array, try Empty versus Null
petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
KzeDag is a list of values

and it still doesn;t work with Empty :(
 
Try this

If KzeDag.Value = Null Or KzeDag.Value = "" Then
dag = "**"
Else
dag = KzeDag.Value
End If
Stop petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
no it still doesn't work.
I solved it like this and it works now, but I still think the other way was good. could there be an error in vba?

If KzeDag.Value <> &quot;&quot; Then
dag = KzeDag.Value
Else: dag = &quot;**&quot;
End If
 
Try this

If IsNull(KzeDag.Value) Or KzeDag.Value = &quot;&quot; Then
dag = &quot;**&quot;
Else
dag = KzeDag.Value
End If

I know this appears to be the same as petersdaniel's code, but this function seems to work better in a lot of cases....don't ask me why. A+, N+, MCP
 
It isn't possible to test for a Null value by using if x = null then .....

That is why the correct method of testing: If isnull(x) then... gives you the correct answer and the other doesn't, as the incorrect method never goes to the THEN part but always to the ELSE one.

Print out the help files to NULL, EMPTY and &quot;&quot; (empty strings) and read them 400 times to see the difference between them. After a while, about six months, you can tell the difference with no more than 45 mins of thinking. :)

Carol
Berlin, Germany
 
Deep in the back of my mind I knew this was true, but I have been spanked for being wrong in the forums so I tossed in an escape clause...ha ha

The IsNull() function is your friend....its also handy to toss a Not in front of it to reverse the logic. A+, N+, MCP
 
Hi,

It's also possible to verify if a value is null
doing

if vartype(Ctrl) = vbnull then

the thing I don't know is if there is one better than the other.

Salvatore Grassagliata
GrassagliataS@hotmail.com
 
That's what we like about Microsoft. 100 ways to get something done and no absolute authority on what is the best...

That's why Tek-Tips is here!!!! petersdaniel@hotmail.com
&quot;If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut.&quot; --Albert Einstein

 
Choctaw, it took me 10 hours of searching through an Access Database I was working on, help files, knowledge base, etc. etc. before I found the problem, why it was a problem and what the cure was, so never forgot it.

Petersdaniel, you are right about the 100 ways to do something. It is like English as compared to other languages. :)

I am very glad about this forum and others (what is the plural of forum?), keep it up.

Carol
Berlin, Germany
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top