Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Docmd.RunSQL to update data

Posted on 2008-06-15
12
Medium Priority
?
427 Views
Last Modified: 2013-11-27
I am trying to do the following:

Update Table TMain to set PendingTX in Table TMain to True when PendingTx is False, Ordered is Null Hold=False and Date()-DateEnter >89.   DateEnter, Hold, Ordered, and PendingTx are all in Table TMain.

Here is my syntax but it is not correct.

DoCmd.RunSQL "UPDATE TMain SET TMain.[PendingRx] = True _
    Where (TMain.PendingTx=False AND TMain.Ordered Is Null AND TMain.Hold=False AND (Date()-TMain.DateEnter>89)"
   

Where is my error to get this to execute correctly?

Thank you.
0
Comment
Question by:thandel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21788628
here is the correction:

DoCmd.RunSQL "UPDATE TMain SET TMain.[PendingRx] = True " _
    & " Where (TMain.PendingTx=False AND TMain.Ordered Is Null AND TMain.Hold=False AND (Date()-TMain.DateEnter>89)"
    

Open in new window

0
 

Author Comment

by:thandel
ID: 21788693
I got a run-time error, missing ),], or tiem in query expression.  I don't see where the error is though.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 21788706
you have indeed a missing ) at the end:
DoCmd.RunSQL "UPDATE TMain SET TMain.[PendingRx] = True " _
    & " Where (TMain.PendingTx=False AND TMain.Ordered Is Null AND TMain.Hold=False AND (Date()-TMain.DateEnter>89) )"

Open in new window

0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:thandel
ID: 21788722
Thanks that was it, however it is not updating PendingTx to True when the condition are met.

(I corrected the variables, I originally had them wrong but it is not updating PendingTx.

DoCmd.RunSQL "UPDATE TMain SET TMain.[PendingTx] = True " _
    & " Where (TMain.PendingTx=False AND TMain.Ordered Is Null AND TMain.Hold=False AND (Date()-TMain.DateEnter>89))"
0
 

Author Comment

by:thandel
ID: 21788730
If I remove (Date()-TMain.DateEnter>89) then it works.
0
 

Author Comment

by:thandel
ID: 21788733
DateEnter is formated as Date/Time
0
 

Author Comment

by:thandel
ID: 21788842
DateEnter is formated as Date/Time.  All the data in this field is just a date, without any time information.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 21788849
Are you sure you have entries more than 89 days old.
Create a select query to check..

Select  Tmain.Dateenter, Date()-TMain.DateEnter as DtDiff  Where TMain.PendingTx=False AND TMain.Ordered Is Null AND TMain.Hold=False
0
 

Author Comment

by:thandel
ID: 21790751
Thanks I had the evaluation backwards.
0
 

Author Comment

by:thandel
ID: 21790753
Are you able to tell me where I went wrong with this command?

        DoCmd.RunSQL "UPDATE TMain SET TMain.[Ordered] = Format(Now(),"" mm-dd-yy"")," & _
        "TMain.[Ref] = UCase(Forms!FTxSuccess!OrderRef)," & _
        "TMain.[PendingRx] = False" & _
        "Where (TMain.PendingTx = True AND (Date()-TMain.DateEnter>89))"
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21791064
yes: you are missing a space between the "FALSE" and the "WHERE" ..

  DoCmd.RunSQL "UPDATE TMain SET TMain.[Ordered] = Format(Now(),"" mm-dd-yy"")" & _
        " ,TMain.[Ref] = UCase(Forms!FTxSuccess!OrderRef)" & _
        " ,TMain.[PendingRx] = False " & _
        " Where (TMain.PendingTx = True AND (Date()-TMain.DateEnter>89) )"

Open in new window

0
 

Author Comment

by:thandel
ID: 21794579
Thanks, I"m trying to learn this you are very helpful but I can't believe how picky it is.    I'm used to use the Macro codes in the macro module and I am trying to use more VBA.

Thanks again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question