Increment Date by 1 day (VBA)

LEXCERM

Active Member
Joined
Jun 26, 2004
Messages
320
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to increment dates by one day in a loop, but I keep getting a Type Mismatch Error.

Here is the code:-

IncrementDate = "#" & [Forms]![frm_Schedule]![txt_StartDate] + 1 & "#"

Do Until IncrementDate = EndDate
sqlDaily = "INSERT INTO tbl_Schedules (ID_Date, ID_SchedData)" & _
"VALUES (" & IncrementDate & ", " & IdSchedData & ");"
CurrentDb.Execute sqlDaily

IncrementDate = IncrementDate +1
IncrementDate = DateAdd("d",1, IncrementDate)

Loop

The first line updates the initial start date by one day, then goes into the loop. The CurrentDB.Execute works fine, but the code
errors at IncrementDate = IncrementDate +1 or DateAdd. I tried wrapping it with ## but always errors.

Can someone please show me the error of my ways! :-S

Many thanks.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
It looks and sounds like txt_StartDate is formatted as Text and not Date.
If you want it to behave like a date, you need to format it as a Date, or convert it to date in your code before you can add 1 to it.
 
Upvote 0

Forum statistics

Threads
1,221,846
Messages
6,162,376
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top