Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using Docmd.RunSQL to update data

Posted on 2008-06-15
12
Medium Priority
?
429 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 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

916 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