A string using a number, need help please

gvelix

New member
Local time
Today, 07:36
Joined
Jan 28, 2008
Messages
8
Hi!, I need a little help please, here is my problem:

I've created a report and Its composed by 3 sub-strings that generate a final string that filter a report. 2 of these sub-strings are text, and they work fine, but the other sub-string is a number and when I try to use this string (to sort the data by year, by the way) I get the following error:

"Data type mismatch in criteria expression"

I know that I have to define that its a number and not text, but I dont know how:

' Build criteria string from lstYear listbox
For Each varItem In Me.lstYear.ItemsSelected
strYear = strYear & ",'" & Me.lstYear.ItemData(varItem) _
& "'"
Next varItem
If Len(strYear) = 0 Then
strYear = "Like '*'"
Else
strYear = Right(strYear, Len(strYear) - 1)
strYear = "IN(" & strYear & ")"
End If

Your help would be greatly appreciated!
Thanks!
 
Dim strSTRING as String

" & strSTRING & " = Number String
'" & strSTRING & "' = Text String
#" & strSTRING & "# = Date String

So depending on what format you have saved your data in the tables you have to reference them via that format.. follow?

sort your code formatting out aswell tbh it will benefit you just as much as anyone else trying to read it! Anyways what i've given you should help you out shout back if your still stuck!

cheers
 
Sorry, here is formatted:


Code:
  ' Build criteria string from lstYear listbox
    For Each varItem In Me.lstYear.ItemsSelected
        strYear = strYear & ",'" & Me.lstYear.ItemData(varItem) _
        & "'"
    Next varItem
    If Len(strYear) = 0 Then
        strYear = "Like '*'"
    Else
        strYear = Right(strYear, Len(strYear) - 1)
        strYear = "IN(" & strYear & ")"
    End If

Thanks for your help!, I'll see what happens!
 

Users who are viewing this thread

Back
Top Bottom