SQL Question Again - (hit enter and sent first attempt)

Discussion in 'MCSD' started by =?Utf-8?B?U29mdFNwb3Q=?=, Sep 18, 2004.

  1. Trying to create a search string to handle searching within an MSAccess TEXT
    field. Having problems when the variable is numeric
    Tried: (spaces expanded for clarity)

    strWhere = strFieldName & "= ' " & cstr(vVariable) & " ' " - raised an error
    when vVariable is numeric

    tried testing for numeric value first:
    if IsNumeric(vVariable) then
    strWhere = strFieldName & "=" & val(vVariable)
    else
    strWhere = strFieldName & "= ' " & cstr(vVariable) & " ' "
    end if

    This also didn't work. What's the work around on this?
    Thanks in advance for any help offered
    Owen Schwer
    =?Utf-8?B?U29mdFNwb3Q=?=, Sep 18, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?U29mdFNwb3Q=?=

    Guest Guest

    Post question of this sort to the following:
    microsoft.public.access.queries
    microsoft.public.vb.general.discussion
    WKidd

    "SoftSpot" <> wrote in message
    news:...
    > Trying to create a search string to handle searching within an MSAccess

    TEXT
    > field. Having problems when the variable is numeric
    > Tried: (spaces expanded for clarity)
    >
    > strWhere = strFieldName & "= ' " & cstr(vVariable) & " ' " - raised an

    error
    > when vVariable is numeric
    >
    > tried testing for numeric value first:
    > if IsNumeric(vVariable) then
    > strWhere = strFieldName & "=" & val(vVariable)
    > else
    > strWhere = strFieldName & "= ' " & cstr(vVariable) & " ' "
    > end if
    >
    > This also didn't work. What's the work around on this?
    > Thanks in advance for any help offered
    > Owen Schwer
    >
    Guest, Sep 18, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?U29mdFNwb3Q=?=

    Tom Dacon Guest

    For numeric values, it's:
    strWhere = strFieldName & "=" & cstr(vVariable)
    you want it come out something like:
    WHERE Price = 12

    for string values, you need to enclose the string in single-quotes, so it:
    strWhere = strFieldName & "= ' " & vVariable & " ' "
    you want it to come something like:
    WHERE State = 'Washington'

    There are better places than this to post programming questions, especially
    something like a question about an SQL query. Microsoft has many newsgroups
    that are devoted to programming subtopics. Why on earth would you post this
    to a newsgroup that's dedicated to Microsoft MCSD certification instead of
    one of those?

    Tom Dacon
    Dacon Software Consulting


    "SoftSpot" <> wrote in message
    news:...
    > Trying to create a search string to handle searching within an MSAccess

    TEXT
    > field. Having problems when the variable is numeric
    > Tried: (spaces expanded for clarity)
    >
    > strWhere = strFieldName & "= ' " & cstr(vVariable) & " ' " - raised an

    error
    > when vVariable is numeric
    >
    > tried testing for numeric value first:
    > if IsNumeric(vVariable) then
    > strWhere = strFieldName & "=" & val(vVariable)
    > else
    > strWhere = strFieldName & "= ' " & cstr(vVariable) & " ' "
    > end if
    >
    > This also didn't work. What's the work around on this?
    > Thanks in advance for any help offered
    > Owen Schwer
    >
    Tom Dacon, Sep 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Au79
    Replies:
    1
    Views:
    377
    Gary G. Taylor
    Mar 10, 2006
  2. Gary Edstrom
    Replies:
    36
    Views:
    1,959
    Walter Banks
    Nov 30, 2007
  3. Lawrence D'Oliveiro

    The First Hit Is Free, But...

    Lawrence D'Oliveiro, Nov 9, 2008, in forum: NZ Computing
    Replies:
    0
    Views:
    308
    Lawrence D'Oliveiro
    Nov 9, 2008
  4. Kiran
    Replies:
    4
    Views:
    664
  5. Happy_Life
    Replies:
    1
    Views:
    329
    Kian Wah Lai
    Nov 30, 2003
Loading...

Share This Page