Results 1 to 9 of 9

Thread: [RESOLVED] Yes/No instead of True/False

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Resolved [RESOLVED] Yes/No instead of True/False

    Hello
    I'm looping through my access table fields and my listview subitems to retrieve data and display it in listview.
    Code:
     Do While Not RS.EOF
      With lvw.ListItems.Add(, , Format(RS!MyDate, "yyyymmddHHMMSS"))
     .SubItems(1) = Format(RS!MyDate, "dd-mm-yyyy")
          For i = 2 To 16
      .SubItems(i) = RS.Fields(i + 1).Value
        Next
        End With
       RS.MoveNext
    Loop
    The output in the listview is either True or False.
    I need to replace True/False format in the listview with Yes/No.
    I tried to change the format in the access but still displaying True/False in the listview.
    Thank you

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Yes/No instead of True/False

    What is the field in the DB? If it's a bit, you can have it output whatever you want as part of the SQL. If it is just a string, that would be harder, though still possible if the formatting of the string is reasonable (it's possible anyways, it just gets a lot less pleasant if the format isn't consistent). You could add a CASE statement to transform the data into whatever you want it to display as.
    My usual boring signature: Nothing

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Yes/No instead of True/False

    Code:
    .SubItems(i) = YesNo(RS.Fields(i + 1).Value)
    
    ...
    
    Public Function YesNo(ByVal bValue As Boolean) As String
      If bValue Then YesNo = "Yes" Else YesNo = "No"
    End Function

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: Yes/No instead of True/False

    Thank you gentelmen for the quick reply
    What is the field in the DB?
    My fields are Boolean

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: Yes/No instead of True/False

    Arnoutdv thank you for the help
    I'm having a type mismatch error
    Code:
    .SubItems(i) = YesNo(RS.Fields(i + 1).Value)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: Yes/No instead of True/False

    Arnoutdv
    I must note that I'm having Yes/No instead of True/False on the listview but the error pops up.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: Yes/No instead of True/False

    I could avoid the message error by adding
    Code:
    On error resume next

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Yes/No instead of True/False

    That means that the contents of the field is not converting to a Boolean. If you have any Null values in the column, that would be an issue. Otherwise, you might try:
    Code:
    .SubItems(i) = YesNo(CBool(RS.Fields(i + 1).Value))
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: Yes/No instead of True/False

    Code:
    .SubItems(i) = YesNo(CBool(RS.Fields(i + 1).Value))
    that did the job
    thank you a lot

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