The VBA CStr function converts an expression into a String data type.
The syntax of the function is:
Where the Expression argument is the expression that that you want to convert to a String.
The following VBA code shows how the CStr function can be used to convert different types of expression (Integer, Boolean and Date) into String data types.
' Convert Integer, Boolean and Date expressions into Strings
Dim str1 As String
Dim str2 As String Dim str3 As String
str1 = CStr( 10 )
' str1 is now equal to the string "10"
str2 = CStr( True )
str3 = CStr( #1/1/2016# )' str2 is now equal to the string "True" ' str3 is now equal to the string "1/1/2016" |
After running the above VBA code, the variables str1, str2 and str3 are equal to the strings "10", "True" and "1/1/2016" respectively.