Insert each date record for current month in Access table using VBA

后端 未结 4 993
无人共我
无人共我 2020-12-12 05:19

I am new with VBA programming. I have designed one form in which there is a button. After clicking this button I want to insert record in my table having one date column. Th

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 06:10

    You can create a table containing every possible day number

    [DayOfMonth]
    
    dd
    --
     1
     2
     3
    ...
    30
    31
    

    and then just use a query like this to generate one row for each day in the current month

    SELECT DateSerial(Year(Date()), Month(Date()), dd) AS IDate
    FROM DayOfMonth
    WHERE Month(DateSerial(Year(Date()), Month(Date()), dd)) = Month(Date())
    

    To use it as an INSERT query would be

    INSERT INTO tbl_ShipOrders (IDate)
    SELECT DateSerial(Year(Date()), Month(Date()), dd) AS IDate
    FROM DayOfMonth
    WHERE Month(DateSerial(Year(Date()), Month(Date()), dd)) = Month(Date())
    

提交回复
热议问题