Results 1 to 5 of 5

Thread: Populating Forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96

    Cool

    Hi,

    Can anyone help me with this problem?

    I am populating a form from a SQL Server database. Some of the columns from the database are NULL and I need to show all the info from the database.

    The form can then be updated. (NULL values may be written back.

    Problem is when I'm assigning my textboxes their values. If the value is NULL I get the error message - invalid use of NULL. I've tried checking to see if the value is null before the assignment but nothing seems to work

    e.g.
    me.txtAddress = !address
    me.txtPhone = !phonenumber

    as I said putting if statements round them to trap the NULL values doesn't work.

    Any ideas?

    H.
    Just trying to muddle through...

  2. #2
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121
    Hollie, I guess your problem is that your way to trap the null values ISN'T right. Bare with me :

    Let's take your example. If you did somehting like this :
    *******************************************************************
    If !address=null Then me.txtAddress="" Else me.txtAddress=!address
    *******************************************************************
    then this is no good! Why? Because : -I quote-: "Expressions that you might expect to evaluate to True under some circumstances, such as If Var = Null and If Var <> Null, are always False. This is because any expression containing a Null is itself Null and, therefore, False."

    You get it ? So instead of what I've written above, you should use :
    *****************************************
    If IsNull(!address)Then me.txtAddress="" Else me.txtAddress=!address
    *****************************************

    The IsNull function returns a Boolean value that indicates whether an expression contains no valid data (Null).

    Plz tell me if that helped ya :-)

    Surgeon

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Have you tried

    Code:
    If IsNull(!address) Then
      Me.txtAddress = vbNullChar
    Else
      Me.txtAddress = !address
    Endif
    Or

    Code:
    Me.txtAddress = IIf(IsNull(!addresss), vbNullChar, !address)
    vbNullChar is effectively a zero length string, when you right the data back this may give you problems since a zero lenght string is NOT Null.

    BTW Why do you allow Nulls in the back-end anyway - that decision alone makes you deserve the pain...

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  4. #4
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Why not just

    Code:
    Me.txtAddress = "" & !address
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96
    Thanks Surgeon and Paul - it works!

    I'll try your suggestion Stevie!

    H.
    Just trying to muddle through...

Posting Permissions

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



Click Here to Expand Forum to Full Width