Results 1 to 7 of 7

Thread: Empty DB field causing grief!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    14

    Empty DB field causing grief!!

    HEllo all,

    Should be a straightforward thing;

    I have queried a table with field1, 2 and 3.
    All fields are not always populated.

    So when I allocated variables to, for instance, field3.
    I will: field3var = rsMyRS![field3]

    Now this will work if the field has got something in it, fair enough. And it the field is empty it will throw an error of :
    invalid use of null
    again, fair enough.

    So to avoid the null error I wanted to put an if loop around like this:

    Code:
    If rsMyRS![field3] Is Null Then
                        Do something else
    End If

    But that doesnt work, and I get an Object required 424 error.

    I have tried :

    Code:
    If rsMyRS![field3] is Empty...
    And also
    Code:
    rsMyRS![field3] = ""
    No luck.
    Any ideas?

    THanks

    Ramo

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Empty DB field causing grief!!

    How about

    Code:
    field3var = rsMyRS![field3] & vbNullString
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    14

    Re: Empty DB field causing grief!!

    Thanks, but...

    Althought that works, I dont think its particularly good coding...
    Is there not a way of checking if a db field is empty before allocating a variable to it.

    Ramo

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Empty DB field causing grief!!

    Try the IsNull function.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    Hyperactive Member Davadvice's Avatar
    Join Date
    Apr 2007
    Location
    Glasgow (Scotland)
    Posts
    440

    Re: Empty DB field causing grief!!

    you could try

    vb Code:
    1. if len(rsMyRS![field3])=0 then

    I normaly use rsMyRS(2) instead of having to type out the field names all the time. I find it easier to use as i can create a query and then add the fields in to excel and return the index by numbering each column.

    cheers

    David
    This is Blank

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    14

    Re: Empty DB field causing grief!!

    isNull is the cookie...

    Thanks for your help (and advice with field references).

    Ramo

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Empty DB field causing grief!!

    I usually use If Not IsNull(whatever) Then

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