Solved

Using Docmd.RunSQL to update data

Posted on 2008-06-15
12
413 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
  • 8
  • 3
12 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
I got a run-time error, missing ),], or tiem in query expression.  I don't see where the error is though.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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
 

Author Comment

by:thandel
Comment Utility
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
Comment Utility
If I remove (Date()-TMain.DateEnter>89) then it works.
0
 

Author Comment

by:thandel
Comment Utility
DateEnter is formated as Date/Time
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:thandel
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks I had the evaluation backwards.
0
 

Author Comment

by:thandel
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now