Results 1 to 13 of 13
  1. #1
    Anetal is offline Novice
    Windows XP Access 2016
    Join Date
    Jan 2021
    Posts
    7

    Jak dodać warunek do funkcji z null

    Hi,


    I have function.

    I need to add iff value is null then "no data".
    How to do it?

    Option Compare Database




    Public Function wyznacz(studScore As Single) As String


    Select Case studScore
    Case 1 To 5
    wyznacz = "do 5"
    Case 6 To 10
    wyznacz = "do 10"
    Case Else
    wyznacz = "pow 10"
    End Select
    End Function

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Code:
    If IsNull(studScore) Then
      wyznacz = "no data"
    Else
      Select Case studScore
        Case 1 To 5
           wyznacz = "do 5"
        Case 6 To 10
           wyznacz = "do 10"
        Case Else
           wyznacz = "pow 10"
        End Select
    End If

  3. #3
    Anetal is offline Novice
    Windows XP Access 2016
    Join Date
    Jan 2021
    Posts
    7
    Thanks, but something doesn't work. I have errors in table:



    Option Compare Database


    Public Function wyznacz(studScore As Single) As String




    If IsNull(studScore) Then
    wyznacz = "no data"
    Else
    Select Case studScore
    Case 0 To 5
    wyznacz = "do 5"
    Case 6 To 10
    wyznacz = "do 10"
    Case Else
    wyznacz = "pow 10"
    End Select
    End If
    End Function


    Score wyznacz
    0 do 5
    10 do 10
    2 do 5
    200 pow 10
    100 pow 10

    #Błąd

    #Błąd

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    My guess is that a variable declared as Single can not contain a NULL. Probably get Invalid use of NULL error or similar.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    That suggests that some Score values are not Null, they are empty strings. You can test for this by creating a test query on your data, like
    SELECT * FROM tblYourTable WHERE [Score]="";
    or in code, try

    If Len(studScore) > 0 Then

    EDIT - Never mind. I missed that Score is a number, not text.
    In that case, one could declare as a Variant - or fix the data
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Maybe this:

    Code:
    If Not IsNumeric(studScore) Then
    	wyznacz = "no data"
    Else
    	Select Case studScore
    		Case 0 To 5
    			wyznacz = "do 5"
    		Case 6 To 10
    			wyznacz = "do 10"
    		Case Else
    			wyznacz = "pow 10"
    	End Select
    End If
    End Function

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    I agree with Orange - there ought to be an error when trying to pass a null to a variable of any numeric type. The fact that it isn't being reported is odd. I can't get it to not fail with error 94 or 13, even with On Error Resume Next
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Anetal is offline Novice
    Windows XP Access 2016
    Join Date
    Jan 2021
    Posts
    7
    It dosesn't work. I added a file.
    Attached Files Attached Files

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Since you didn't comment on cross posting (post 7) I imagine you're not going to let anyone know you stated at AWF that this is solved, so I will.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Change the query:


    Click image for larger version. 

Name:	nodata.png 
Views:	20 
Size:	16.3 KB 
ID:	43840

  12. #12
    Anetal is offline Novice
    Windows XP Access 2016
    Join Date
    Jan 2021
    Posts
    7
    Thank you very much. This way is better.

  13. #13
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Glad to help. Please let us know when you ask same question at other forums. We can check there and see if you already have a solution, and save our time without duplicate effort.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Jak dodać warunek do funkcji z null
    By Anetal in forum Modules
    Replies: 1
    Last Post: 01-04-2021, 06:50 AM
  2. Replies: 4
    Last Post: 04-09-2019, 02:05 PM
  3. Replies: 4
    Last Post: 03-11-2017, 09:48 PM
  4. Replies: 7
    Last Post: 11-07-2016, 09:24 AM
  5. Replies: 1
    Last Post: 02-23-2012, 02:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums