A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Testing field for null in Select Case statement



 
 
Thread Tools Display Modes
  #1  
Old May 5th, 2009, 08:39 PM posted to microsoft.public.access
Lars Brownies
external usenet poster
 
Posts: 149
Default Testing field for null in Select Case statement

I have code something like:

Select case fldMyField
Case "All records":
´other code
Case "This employee:
´other code
Case Null: msgbox "This field can't be empty"
Cancel = True
End Select

The case null statement to test if the field is empty is not working.
if isNull(fldMyField) does work

Why doesn't the case Null statement work? What would be the best way to do
this?

Thanks,

Lars


  #2  
Old May 5th, 2009, 09:20 PM posted to microsoft.public.access
[email protected]
external usenet poster
 
Posts: 129
Default Testing field for null in Select Case statement

Comparison with Null results in Null, neither True nor False, which is
the reason for the VBA IsNull function or IS NULL in SQL. This should
work:

Select Case Nz(fldMyField,"")
Case "All records":
´other code
Case "This employee":
´other code
Case "": MsgBox "This field can't be empty"
Cancel = True
End Select

Ken Sheridan
Stafford, England

On May 5, 8:39 pm, "Lars Brownies" wrote:
I have code something like:

Select case fldMyField
Case "All records":
´other code
Case "This employee:
´other code
Case Null: msgbox "This field can't be empty"
Cancel = True
End Select

The case null statement to test if the field is empty is not working.
if isNull(fldMyField) does work

Why doesn't the case Null statement work? What would be the best way to do
this?

Thanks,

Lars


  #3  
Old May 5th, 2009, 09:53 PM posted to microsoft.public.access
Lars Brownies
external usenet poster
 
Posts: 149
Default Testing field for null in Select Case statement

Thanks Ken!

schreef in bericht
...
Comparison with Null results in Null, neither True nor False, which is
the reason for the VBA IsNull function or IS NULL in SQL. This should
work:

Select Case Nz(fldMyField,"")
Case "All records":
´other code
Case "This employee":
´other code
Case "": MsgBox "This field can't be empty"
Cancel = True
End Select

Ken Sheridan
Stafford, England

On May 5, 8:39 pm, "Lars Brownies" wrote:
I have code something like:

Select case fldMyField
Case "All records":
´other code
Case "This employee:
´other code
Case Null: msgbox "This field can't be empty"
Cancel = True
End Select

The case null statement to test if the field is empty is not working.
if isNull(fldMyField) does work

Why doesn't the case Null statement work? What would be the best way to do
this?

Thanks,

Lars



  #4  
Old May 5th, 2009, 10:39 PM posted to microsoft.public.access
meggie1101
external usenet poster
 
Posts: 2
Default Testing field for null in Select Case statement

wat is this
"Lars Brownies" wrote in message
...
I have code something like:

Select case fldMyField
Case "All records":
´other code
Case "This employee:
´other code
Case Null: msgbox "This field can't be empty"
Cancel = True
End Select

The case null statement to test if the field is empty is not working.
if isNull(fldMyField) does work

Why doesn't the case Null statement work? What would be the best way to do
this?

Thanks,

Lars


  #5  
Old May 5th, 2009, 10:43 PM posted to microsoft.public.access
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default Testing field for null in Select Case statement

A Zero-length string, i.e.

"":

is not the same thing as Null !

Why not just use

Case Else
MsgBox "This field can't be empty"
Cancel = True

Thid includes anything except the stated Cases.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200905/1

  #6  
Old May 8th, 2009, 05:15 PM posted to microsoft.public.access
[email protected]
external usenet poster
 
Posts: 129
Default Testing field for null in Select Case statement

(a) Who said it was? I think you need to read the post more
carefully.

(b) We can't assume that the list of values is exhaustive. There may
well be other legitimate values than those for which the case
construct tests.

Ken Sheridan
Stafford, England

On May 5, 10:43 pm, "Linq Adams via AccessMonster.com" u28780@uwe
wrote:
A Zero-length string, i.e.

"":

is not the same thing as Null !

Why not just use

Case Else
MsgBox "This field can't be empty"
Cancel = True

Thid includes anything except the stated Cases.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access/200905/1


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.