Search for a number not a text, SQL

romio

Registered User.
Local time
Yesterday, 16:02
Joined
Apr 20, 2005
Messages
68
I have a form with four combo box that will search for a record, as follow:

Field Name "Printer" , DataType "Text"
Field Name Month" , DataType "Text"
Field Name "Year" , DataType "Number"
Field Name "Day" , DataType "Number"

code for Find Record Button:
Code:
   If Not IsNull(ID) And Trim(ID) <> "" Then
        StrSQL = StrSQL & " And [Id] = " & [ID]
    End If
       
   If Not IsNull([txtname]) And Trim([txtname]) <> "" Then
       If InStr([txtname], "*") = 0 Then
       
            StrSQL = StrSQL & " And [Name] = '" & [txtname] & "'"
       Else
            StrSQL = StrSQL & " And [Name] like '" & [txtname] & "'"
        End If
    End If
    
    '================================'
    
      
    If Not IsNull([txtyear]) And Trim([txtyear]) <> "" Then
        
        If InStr([txtyear], "*") = 0 Then
        
            StrSQL = StrSQL & " And [Year] = '" & [txtyear] & "'"
         Else
            StrSQL = StrSQL & " And [Year] like '" & [txtyear] & "'"
        End If
    
    End If
    
    '================================'
    
       
    If Not IsNull([txtmonth]) And Trim([txtmonth]) <> "" Then
        
        If InStr([txtmonth], "*") = 0 Then
        
            StrSQL = StrSQL & " And [Month] = '" & [txtmonth] & "'"
         Else
            StrSQL = StrSQL & " And [Month] like '" & [txtmonth] & "'"
        End If
    
    End If
    
   '================================'
    
      
    If Not IsNull([txtday]) And Trim([txtday]) <> "" Then
   
        If InStr([txtday], "*") = 0 Then
            StrSQL = StrSQL & " And [Day] = '" & [txtday] & "'"
         Else
        StrSQL = StrSQL & " And [Day] like '" & [txtday] & "'"
        End If
   
    End If
    
    '================================'

This is only a part of the code, I have a problem with year and day since they are numbers not text I was told that i cant use this line:
Code:
StrSQL = StrSQL & " And [Month] like '" & [txtmonth] & "'"
I was told that there is no need to use "like", am not really sure how to do it, any help will be appreciated.

Thanks.
 
If the field is text, the proper SQL syntax is:

[Month] Like "July"

If the field is a number, the proper syntax is:

[Month] = 7

So, you would change your code to:

Code:
StrSQL = StrSQL & " And [Month] = " & txtMonth
 
Thanks ejstefl :)
 

Users who are viewing this thread

Back
Top Bottom