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
The following expression will give you an integer, the number of days in the current month:
Day(DateSerial(Year(Date()), Month(Date())+1, 0))
This is the zeroth day of the following month, which is the last day of the current month. This expression will still work if moving from December to January.
Store this in a variable, say lastDay then use a loop, For x = 1 To lastDay to perform the inserts.
Within the loop, this expression
DateSerial(Year(Date()), Month(Date()), x)
will give you the dates 1/5/2016, 2/5/2016,.., 31/5/2016.
You should also surround the dates with date delimiters # when inserting. Combine this with ISO formatting of the date yyyy-mm-dd (so that months won't be interpreted as days):
VALUES (#" & Format(dtValue, "yyyy-mm-dd") & "#)"
where dtValue is the date you've just formed using the previous DateSerial expression.