Results 1 to 4 of 4
  1. #1
    Al77 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20

    Question Automatic Date Entry

    Can anyone tell me how to design a Query that will add a specific date to a Table every month?



    In my case, I would like to add / append new record entries on the first day of each month - for example.

    Do I have to start with a table that has ALL the future dates required, or is there a sweeter solution?

    Thanks, in advance.

    Al

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    You could do this. Create an Autoexec Macro that calls a Function in a module.

    Public function add_a_date() As boolean
    Dim dtval as date
    Dim rs As new adodb.recordset
    Dim strsql as string, adocmd as new ADODB.Command
    strsql = "Select Max(Datefield) as stdate from your_table "
    rs.open strsql, currentproject.connection,
    If Month(rs!stdate) = Month(Now()) and Year(rs!stdate) = Year(Now()) Then
    add_a_date = False
    Else
    strsql = "Insert Into yourtable Set datefield = Date()"
    adocmd.activeconnection = currentproject.connection
    adocmd.commandtext = strsql
    adocmd.execute
    add_a_date = True 'To show it completed

    End if
    End function

    This is only the base you would also have to add some error handling and other fields that are required for your table.

  3. #3
    Al77 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20
    VERY impressed Ray - I just have to spend sometime trying to understand your coding now!

    Al

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    The initial recordset get's the maximum date stored in that field. You then compare the month and year of that field to the current month and year. If they are the same the routine has already run and doen't need to execute again. If they are different then it inserts a new record into the table

    Note: As written it inserts the date the procedure is executed so if the procedure is run on the second of the month and there is no record for the current month it would insert the second. You could modify that line from
    Set datefield = date() to Set datefield = CVDate(Month(now()) & "/01/" & Year(now()))
    That will put the first of the current month regardless of what the run date is.

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

Similar Threads

  1. Automatic Username On Data Entry
    By netchie in forum Programming
    Replies: 10
    Last Post: 02-17-2012, 03:31 PM
  2. Automatic Recurring Entry
    By Al77 in forum Access
    Replies: 3
    Last Post: 02-15-2012, 04:24 PM
  3. Automatic Field DAta Entry
    By Lupson2011 in forum Access
    Replies: 4
    Last Post: 09-01-2011, 09:15 AM
  4. Access 2003 automatic field entry
    By RANCHLAW56 in forum Forms
    Replies: 6
    Last Post: 12-30-2010, 02:57 PM
  5. Automatic Data Entry on a Specific Date
    By alanbrai in forum Programming
    Replies: 2
    Last Post: 11-14-2007, 05:15 PM

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