Results 1 to 4 of 4
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Date Syntax in vba is wrong ?

    If Me.TransDate(TransDate - 7) And Date And Date And Me.PeriodTypeID = "d" Or "ww" Then

    I want to delete records older than a week from TransDate until today. If the date in TransDate is older than 7 days then delete record(s)


    My syntax is wrong though?

  2. #2
    narang is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    4
    Quote Originally Posted by burrina View Post
    If Me.TransDate(TransDate - 7) And Date And Date And Me.PeriodTypeID = "d" Or "ww" Then

    I want to delete records older than a week from TransDate until today. If the date in TransDate is older than 7 days then delete record(s)
    My syntax is wrong though?
    Hello,

    The following could be a probable solution

    Let the name of the table be table1
    name of the field transdate

    The following code may be enetered on the click event of the command button object

    Dim con As New ADODB.Connection
    Set con = Application.CurrentProject.Connection

    con.Execute "delete from [table1] where (date()-[table1].[transdate])>7", , adCmdText
    con.Close
    Set con = Nothing

    Rgds

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Ok, I tried this but it would not compile?.

    con.Execute "delete from [tblmissedtransactions] where (date()-[tblmissedtransactions].[transdate])>7" And Me.PeriodTypeID = "d" Or "ww", , adCmdText

  4. #4
    narang is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    4
    Quote Originally Posted by burrina View Post
    Ok, I tried this but it would not compile?.

    con.Execute "delete from [tblmissedtransactions] where (date()-[tblmissedtransactions].[transdate])>7" And Me.PeriodTypeID = "d" Or "ww", , adCmdText
    Hello,

    To me it appears that the table name is tblmissedtransactions

    This table has among others 2 fields namely

    1. transdate- This is a date type of field
    2. PeriodTypeID- This is a text type of field

    If the above is correct you may try the following

    Private Sub Command6_Click()
    Dim con As New ADODB.Connection
    Set con = Application.CurrentProject.Connection

    con.Execute "delete from [tblmissedtransactions] where ((date()-[tblmissedtransactions].[transdate]>=7) and (trim(nz([PeriodTypeID]))='d' or trim(nz([PeriodTypeID]))='ww'))", , adCmdText
    con.Close
    Set con = Nothing



    End Sub

    Rgds

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-25-2012, 10:04 PM
  2. Am I doing it wrong? Null Values & Date()
    By the problem in forum Queries
    Replies: 3
    Last Post: 07-25-2012, 01:34 PM
  3. Date Syntax not working
    By Huddle in forum Access
    Replies: 4
    Last Post: 06-27-2012, 11:28 AM
  4. Date Syntax
    By Alex Motilal in forum Forms
    Replies: 3
    Last Post: 10-28-2010, 06:26 AM
  5. Query for latest date? what am I doing wrong?
    By Overdive in forum Queries
    Replies: 1
    Last Post: 12-18-2009, 06:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums