Share via

update table from form query will not work

Anonymous
2019-05-16T01:24:19+00:00

I am trying to update a table from a form with this command

DoCmd.RunSQL "UPDATE Inspections SET Complete=True WHERE WorkOrder=" & WO.Value

where WO is a text field (unbound) on my form. But I always get 0 rows updated. I can manually type in the values I want to update and that works but trying to pull the values from a field does not. How do I resolve?

<The thread has been moved to the correct category by Eli Qian>

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2019-05-16T18:25:05+00:00

    I got it! The single quotes were the answer but I missed the point that I need to oomit all spaces because they count as part of the string

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-05-16T15:58:48+00:00

    1.  What is the data type of the WorkOrder column?

    2.  Was the column by any chance created by means of the lookup field wizard?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-05-16T14:52:05+00:00

    If it doesn't update the table, then something is wrong with the UPDATE statement. Are you sure you're getting the correct WorkOrder value?

    Sometimes it helps to print out the SQL statement before you do this:

    Debug.Print "UPDATE Inspections SET Complete=True WHERE WorkOrder=" & WO.Value

    Do this just before calling the Execute statement. The results should print in the Immediate window.

    Also, if WorkOrder a Text or Numeric value? If it's a Text value, you have to wrap it in quotes:

    "UPDATE Inspections SET Complete=True WHERE WorkOrder='  " & WO.Value & " '  "

    I used single quotes, and added some spaces so you can see it.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2019-05-16T14:08:32+00:00

    hmmmm... no errors but neither does it update the table

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2019-05-16T13:01:09+00:00

    Try using currentdb.Execute instead, with the dbFailOnError argument:

    Currentdb.Execute "UPDATE Inspections SET Complete=True WHERE WorkOrder=" & WO.Value, dbFailOnError

    In some cases, using RunSQL won't show you any errors (depending on other settings in Access, or in VBA).

    Was this answer helpful?

    0 comments No comments