Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264

    Question Unanswered: select case with isNull

    Is there a simple way to include a isNull test within a select case?

    I have to do several different things depending on the value of the field, one of the special cases is if the field is left empty.

    I know that I can write something like

    Code:
     if isnull(txtLookup) then
    	 'special handling for null
    else
       select case txtLookup
    	   case "ROC"
    		   'ROC events
    	   case else
    		   'set Defaults
       End select
    End if
    I find that solution rather ugly however.

    Any thoughts on something that would be a bit better?

    Thanks.

    Steve

  2. #2
    Join Date
    Jul 2004
    Posts
    125
    This way you can test for either Null or an empty string. (Just in case)
    Select Case Nz(txtLookup,"")
    Case Is = ""
    'special handling for ""
    Case Is = "ROC"
    'ROC events
    Case else
    'set Defaults
    End select

  3. #3
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by sps
    Is there a simple way to include a isNull test within a select case?
    I like to use a custom funtion to test for Null. You can do this and set a variable to check in the Select Case.
    Code:
       If Not isNothing(Me.txtLookup) Then
          strVal = Me.txtLookup
       Else
          strVal = ""
       End If
    
       select case strVal 
    	   case "ROC"
    		   'ROC events
    	   case else
    		   'set Defaults
       End select
    
    -------------------
    this isNothing function found on tek-tips
    http://www.tek-tips.com/faqs.cfm?fid=4469
    
    Public Function IsNothing(pvar As Variant)
        On Error Resume Next 'Handle errors here
        IsNothing = (pvar Is Nothing)
        On Error GoTo 0 'Reset error handling
    End Function
    You can make a module for frequently used functions and use it in any projects you create
    ~

    Bill

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •