Results 1 to 3 of 3

Thread: Checking database fields for no data

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Checking database fields for no data

    My program reads Access DB table. I use the following code to make sure I only read the field if the data is there:
    Code:
      If (rs.Fields("COMMNT1") <> vbNull) Then
        strCOMMNT1 = Trim(rs.Fields("COMMNT1"))
      End if
    However if the field is empty I get an error on the vbNull line. I'm thinking checking against the vbNull is not the right way to do it. How do I check for an empty field?
    Thanks

    Tomexx.

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Checking database fields for no data

    The easier way to do this and not get the invalid use of null message would be:
    vb Code:
    1. strCOMMNT1 = Trim(rs.Fields("COMMNT1) & vbNullString)

    This appends a null string ( empty string value '') to the database fields then performs the trim.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

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

    Re: Checking database fields for no data

    You could also do
    Code:
    If Not IsNull(rs.Fields("COMMNT1")) Then
        strCOMMNT1 = Trim(rs.Fields("COMMNT1"))
    End if

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