-
Feb 12th, 2018, 05:05 PM
#1
Thread Starter
Fanatic Member
[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
-
Feb 12th, 2018, 05:15 PM
#2
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
-
Feb 12th, 2018, 05:16 PM
#3
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
-
Feb 12th, 2018, 05:46 PM
#4
Thread Starter
Fanatic Member
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
-
Feb 12th, 2018, 05:47 PM
#5
Thread Starter
Fanatic Member
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)
-
Feb 12th, 2018, 05:56 PM
#6
Thread Starter
Fanatic Member
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.
-
Feb 12th, 2018, 05:58 PM
#7
Thread Starter
Fanatic Member
Re: Yes/No instead of True/False
I could avoid the message error by adding
Code:
On error resume next
-
Feb 12th, 2018, 06:10 PM
#8
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
-
Feb 12th, 2018, 06:34 PM
#9
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|