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

后端 未结 4 1004
无人共我
无人共我 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:13

    Here's a fancy query that will return a month's dates:

    SELECT DISTINCT 
        10 * Abs([Deca].[id] Mod 10) + Abs([Uno].[id] Mod 10) AS Id, 
        DateAdd("d",[Id], DateSerial(Year(DateOfMonth), Month(DateOfMonth), 1)) AS [Date]
    FROM 
        msysobjects AS Uno, 
        msysobjects AS Deca
    WHERE 
        (10*Abs([Deca].[id] Mod 10) + Abs([Uno].[id] Mod 10)) < Day(DateSerial(Year(DateOfMonth), Month(DateOfMonth)+1, 0))
    

    That said, I would write a loop adding records to a recordset using VBA, not the slow SQL call of yours.

提交回复
热议问题