Results 1 to 5 of 5

Thread: Auto delete in VB-Access97 by date?

  1. #1
    Scorpio
    Guest

    Question

    Hi!

    I have an VB6 project that uses an MS Access97 database.
    I want to autodelete posts that are older than 10 days. I have a date column in my DB.
    How do I do?
    Can I make it in VB or in Access or in both?? The easiest way?

  2. #2
    Member
    Join Date
    Nov 2000
    Location
    Brisbane, Australia
    Posts
    44
    If you run this program daily, perform this query in the Load event for your main form:

    Code:
    DELETE [Table1].*
    FROM [Table1]
    WHERE (((Date())>[Table1].[DateField]+10));
    Where [Table1] is your table and [DateField] is the field you judge the age by.

    If you don't run it daily - I'm not sure.
    Boring signature included.

    VB6 SP3.

  3. #3
    Guest

    Question Thanx but...

    ...VB complains about the asterisk (*) after the Delete line and the ";" after the Where line.
    I made it like this:
    Code:
    Delete grdDataGrid.*
    From grdDataGrid
    Where (((Date) > grdDataGrid.Columns(0) + 10));
    But it complains on this and that...
    Because i made this program from an wizard, i might got it all wrong with the values.

  4. #4
    Guest

    Question Anyone??

    Anyone??

  5. #5
    Member
    Join Date
    Nov 2000
    Location
    Brisbane, Australia
    Posts
    44
    Sorry,

    This is an SQL Query.

    You will need to set up a string and use it as the basis for a recordset using ADO - if you don't know how, there are tons of threads on this site that you can search for to find out (that's how I learned and I'm still not very good):

    Code:
      Dim adoDataCn As ADODb.Connection
      Dim adoDataRs As ADODb.Recordset
      Dim strDataCn As String
      Dim strSQL As String
    
    ' Set up connection etc here - if you don't know how, search this site for connection string and you'll be able to work it out - that's how I learnt.
    
    ' then set up SQL string
      strSQL = "DELETE [Table1].* " & _
      "FROM [Table1] " & _
      "WHERE (((Date())>[Table1].[DateField]+10));"
    
    ' and execute the deletion
       Set adoDataRs = adoDataCn.Execute(strSQL, , adCmdText)
    Boring signature included.

    VB6 SP3.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width