Consulting

Results 1 to 3 of 3

Thread: Wildcard in SQL

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Wildcard in SQL

    Hi folks
    Not been on for a while

    How do I use a wildcard value in an SQL

    heres my SQL
    [VBA]Private Sub BuildList(cGroup As String, cType As String, active As Boolean)
    Dim qry As String
    Dim idx As Long, icon As Long

    qry = "SELECT TblComponentDetail.ComponentID, TblComponentDetail.ComponentGroupID, " & _
    "TblComponentDetail.ComponentTypeID, TblComponentDetail.ActiveToDate, " & _
    "TblComponentDetail.Description, TblComponentDetail.ActiveFlag, TblComponentDetail.Make, " & _
    "TblComponentDetail.Model " & _
    "FROM TblComponentDetail " & _
    "WHERE (((TblComponentDetail.ComponentGroupID)='" & cGroup & "') " & _
    "AND ((TblComponentDetail.ComponentTypeID)='" & cType & "') " & _
    "AND ((TblComponentDetail.ActiveToDate)>Now()) " & _
    "AND ((TblComponentDetail.ActiveFlag)=True));"[/VBA]

    If I dont know cType when I run the SQL what value should I use to represent cType when calling the routine e.g.

    [VBA]Call BuildList(cGroup, "*", True)[/VBA]

    I have tried
    like"*" but that comes up with a mismatch error
    I have tried just * and _
    but no joy.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Probably not the best solution but what about an if clause to check if ctype is known. If it's blank, don't include this field in your query and perform the query without this field.

    Charlize

  3. #3
    Try % instead of * and _ instead of ?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •