Results 1 to 6 of 6

Thread: Null field

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Malaysia
    Posts
    69
    If in Access 2000, I have a field a text field with no data inside. Then in VB6, when I assign that field to a text box, I get a error with 'Invalid use of null'. I have to place a if statement before the assign statement to make sure the field is not equal to "", only then I will assign it. This will prevent the error but it is very troublesome if I have about 20 to 30 field to check.

    Is there any option or way that I can use without having checking for empty text field ? If it just an empty field, just assign a empty string to it.

    Thanks


  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    I have a little function, that does exactly what you want

    Code:
    Public Function Field_Empty(s) As String
              If IsNull(s) Then
                Field_Empty = ""
              Else
                Field_Empty = s
              End If
    End Function
    you call the funtion this way:
    Code:
    Text1.Text = Field_Empty(Recordset!Fieldname)
    Hope, this helps



  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Try the following instead of IF statements :

    Code:
    TextBox.Text = "" & rs!Field
    Hope this helps

  4. #4
    Addicted Member LAURENS's Avatar
    Join Date
    Jan 2000
    Location
    Utrecht, the Netherlands
    Posts
    138
    You could set the Allow Zero length property of the fields to Yes in Access.

    I usually assing values to strings by concatenating them to an empty string.

    strString = "" & tblTable!Adress
    or the other way round
    tblTable!Adress = "" & Text1 before updating the record.
    Regards,
    Laurens

    Using VB5 Enterprise edition SP3
    VB6 Enterprise edition SP5

  5. #5
    New Member
    Join Date
    Jun 2000
    Posts
    8
    Im not 100% on this but it should work

    In your database if you set the Default Value of your text fields to Null then VB should allow you to use VbNull when checking the field.


  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Malaysia
    Posts
    69
    Thanks for all the replies... My problem solved.

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