Results 1 to 10 of 10

Thread: empty textboxes - null values

  1. #1
    Join Date
    Apr 2003
    Posts
    14

    Question empty textboxes - null values

    I would like a procedure to act in different ways according to the value in a particular textbox even if the content of that textbox is "" (i.e. that textbox is empty).

    I have tried it in a conditional statement like this:


    select case me!textbox
    case ""
    ...do something nice...
    case "B"
    ...blalbakjb...
    case else
    ...bblalsabls....
    end select


    This doesn´t work though - the procedure stops and an error message appears saying something like "illegitimate use of a null-value". I have also tried it with case isempty(me!textbox) or case isnull(me!textbox) but it doesn´t work either way.

    Any suggestions?

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    dim x as string

    if isnull(me!textbox) then
    x = "NULL"
    end if

    select case x
    case "NULL"
    ...do something nice...
    case "B"
    ...blalbakjb...
    case else
    ...bblalsabls....
    end select

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Also add this

    If IsNull(Me!Text0) Or Me!Text0 = "" Then
    x = "NULL"
    End If

  4. #4
    Join Date
    Apr 2003
    Posts
    14
    thanks for your suggestions.

    the funny thing is, although they look straight-forward, they don´t work on my machine. I am using office xp. I have tried every single suggestion of yours but the only thing I get is an error message saying "illegitimate use of null" This this makes me really break out in hives...

    ok could it be that my string value for some weird reason is not allowed to be assigned null values or something?

    hmmmm

  5. #5
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    In design view- right click on your text box and see whether you have any validation rule or input mask.

  6. #6
    Join Date
    Apr 2003
    Posts
    14

    no no no no

    I have checked, but there is no validation rule. I don´t know what an input mask is but I have looked up the properties of that field in design view and I haven´t found anything that even comes close to that.

    Let´s recap:
    1)
    I have tried it with a conditional statement asking for the value of the field in question like

    select case field
    case ""
    ......
    case else
    .....
    end select

    2)
    I have tried it the way MAK suggested it:

    dim x as string
    if isnull(me!textbox) then
    x = "NULL"
    end if
    select case x
    case "NULL"
    ...do something nice...
    case "B"
    ...blalbakjb...
    case else
    ...bblalsabls....
    end select

    I have also tried to replace the if-statement with

    If IsNull(Me!Text0) Or Me!Text0 = "" Then
    x = "NULL"
    End If

    3) There doesn´t seem to be a validation rule that doesn´t allow the field to be empty

    The problem is, whenever the procedure is started an error message pops up saying "illegitimate use of null"

    Be honest all Access-Gurus out there: is this logical?? Is my computer possessed by an alien force??

    I am starting to wonder whether one can solve the simplest problems with access at all.

    Thanks in advance for further helpful hints, Bruno

  7. #7
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Pal.

    dont give up so soon.

    create a sample form and procedure (which can reproduce the problem) in a access database and upload it here. let me see whats happening.

    -MAK

  8. #8
    Join Date
    Apr 2003
    Posts
    14
    thanks for your generous offer and for not giving up on me.

    I have created an access-file that reproduces the error. If you press the button on the form without selecting anything in the combo-box the mysterious null-error pops up.
    Attached Files Attached Files

  9. #9
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Try this......

    Dim city As String
    Dim city_sentence As String
    'city = Me!city

    If IsNull(Me!city) Then
    city = "NULL"
    else
    city=Me!city
    End If

    msgbox city

    Select Case city
    Case "NULL"
    city_sentence = "We don´t want to travel anywhere today!"
    Case Else
    city_sentence = "We would like to fly to " & city & " today!"
    End Select

    Reports!two!citytext.Visible = 1
    Reports!two!citytext = city_sentence

  10. #10
    Join Date
    Apr 2003
    Posts
    14

    Cool it works!

    Your code does the trick!

    Thanks a lot for bearing with me and helping me out!


Posting Permissions

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