Record selection based on a conditional

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimleon
    New Member
    • Nov 2006
    • 74

    Record selection based on a conditional

    Hello All

    I am trying to select a record to edit using the following commands

    query = "select * from companies where name=" & Forms![Main Details]![CO_NAME]

    Set record = dbbooking.OpenR ecordset(query)

    Forms![Main Details]![CO_NAME] is pointing to 'dummy co'

    but i get this error when attempting to select the record

    Syntax error (missing operator) in query expression 'name=dummy co'

    I have tried putting companies and name in square brackets but it doesn't affect it!

    Any clues out there?

    Many thanks in advance
  • abouddan
    New Member
    • Feb 2007
    • 42

    #2
    Originally posted by jimleon
    Hello All

    I am trying to select a record to edit using the following commands

    query = "select * from companies where name=" & Forms![Main Details]![CO_NAME]

    Set record = dbbooking.OpenR ecordset(query)

    Forms![Main Details]![CO_NAME] is pointing to 'dummy co'

    but i get this error when attempting to select the record

    Syntax error (missing operator) in query expression 'name=dummy co'

    I have tried putting companies and name in square brackets but it doesn't affect it!

    Any clues out there?

    Many thanks in advance

    First I think we should know the format of the field "Name" in the table "companies" . If it's a text so your query should be :
    Code:
    query= "select * from companies where name='" & Forms![Main Details]![CO_NAME] & "'"
    You just have to add a single quote after (name=) and another one in the end of the query. so it's : Double quote, single quote, double quote (" ' ") without any space.
    Last edited by NeoPa; May 2 '07, 12:37 PM. Reason: Tags

    Comment

    • jimleon
      New Member
      • Nov 2006
      • 74

      #3
      Cheers, that worked a treat!


      Originally posted by abouddan
      First I think we should know the format of the field "Name" in the table "companies" . If it's a text so your query should be :
      Code:
      query= "select * from companies where name='" & Forms![Main Details]![CO_NAME] & "'"
      You just have to add a single quote after (name=) and another one in the end of the query. so it's : Double quote, single quote, double quote (" ' ") without any space.

      Comment

      Working...