how to create a "for...next" loop in VBA

G

Guest

I want the code to insert a given name to a field in a form for a period of
time for which I give the start and end date. e.g I want to fill the name of
a person in a field for a reservation form if I give the start and end date
of the reservation
 
G

Guest

I don't think you gave enough information to get a perfect answer, but in
this case, I don't believe it is a For Next loop you want, but rather a Do
Loop. That is because it is based on dates. You could use a For Next by
populating a variable with the results of a DateDiff function
lngLoop = DateDiff("d",StartDate, EndDate)

But I would do it like this:

Dim dtmCheckDate As Date

dtmCheckDate = StartDate

Do Until dtmCheckDate = EndDate
'Whatever you need to do here
dtmCheckDate = DateAdd("d", 1, dtmCheckDate)
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top