Do...While Loop?

ConfusedStudent

New member
Local time
Today, 17:01
Joined
Apr 1, 2011
Messages
1
Hi There!

I am new to all of this and desperately confused! I am learning Access 2007 but found out yesterday that my teacher has never used it herself!! No wonder I don't know what I'm doing! If anyone can offer me some help I would be REALLY grateful because I don't want to fail my course having spent a fortune on it!

I've bought loads of books and scanned the internet & unfortunately most of it seems like gobbaldygook to me! I think I've worked out though that I need a D0..While Loop.

I have got a list of dates in a table which tells me when the DVD store is open. It is also closed at weekends. I need to be able to put today's date into a form which will then generate a due date and return date. The due date is 14 days after today. But if the shop is closed then the return date is the next day that the shop is open.

PLEASE can anyone help? - I'm desperate!

Thanks
 
Welcome to the forum.

Finding the due day is quite easy to achieve using a simple formula (although you could also use a Do While). Look at it this way, you have a nice list of Open days in a table. The date you are interested in is the first date on or after the 14th day after the loan date. Since the table does not contain any closed dates then simply following this rule will give you the required date.

This can be thought of in two steps:
- List all the dates on or after the 14th day
- Find the earliest date from this list

We can use the DMIN function to achieve the above. DMIN will find the “earliest” from the list. The criteria for DMIN can be set to list all the dates on or after the 14th day.

I’ll leave you to work out the exact syntax since you are the student. ;)

Good luck with your studies.

Hth

Chris
 
often you need to do something for a number of times - for this you need a loop

if you know you want to do something a set number of times, then use for..next

so this does something 100 times
Code:
[B]for somevar = 1 to 100
 do stuff
next[/B]


now often you don't know how many times you want to do something - so you use a boolean test, either with a while..wend loop, or a repeat..until loop

Code:
[B]do
while sometest_is_true
  do stuff
wend
loop[/B]

or

Code:
[B]do
repeat
   do stuff
until sometest_is_false
loop[/B]

note that at some point, something needs to change the control test, or the loop will repeat forever. (although you can use code to "breakout" of the loop.
This can be something happening within this code, or something caused by an event elsewhere in your app


While.. wend is probably more accurate than repeat ..until - in that repeat.. until must execute once, but while.. wend may not execute at all

note that you don't have to put the words do ... loop, around a while ..wend construct. I think they are necessary around repeat..until


------------
messing with dates, and excluding weekends etc, is surprisingly tricky to do directly. there are lots of examples here, though.

good luck
 
Last edited:
Code:
[B]do[/B]
[B]while sometest_is_true[/B]
[B]do stuff[/B]
[B]wend[/B]
[B]loop[/B]

That is an endless loop because both Do-Loop and While-Wend are loops in their own right. In this example the Do-Loop has no condition and is thus endless.

Code:
[B]do[/B]
[B]repeat[/B]
[B] do stuff[/B]
[B]until sometest_is_false[/B]
[B]loop[/B]

There are many forms of the loop in VBA.
Repeat is not one of them.
Where did you get that from, Dave?

Here are the loops I can think of off the top of my head:

Code:
Do While {test}
Loop
 
Do
Loop While {test}
 
Do Until {test}
Loop
 
Do
Loop Until {test}
 
While {test}
Wend
 
For i = x To y Step z   '  (Step z is optional)
Next
 
For Each x In y
Next
 
Last edited:
wow - my bad obviously

I only EVER use for..next and while .. wend

I never include do and loop (i don't think anyway)

I just THOUGHT the correct official syntax was to have do ... loop around the construct.

repeat .. until is Pascal - I unconconsciously thought it was correct in VBA - as I say, I only ever use while .. wend, rather than do..until - because while..wend does not have to execute, which can never be wrong.
 
I just THOUGHT the correct official syntax was to have do ... loop around the construct..

While is certainly an odd case as it is both a loop in its own right when used with Wend and a keyword in a Do Loop.

repeat .. until is Pascal - I unconconsciously thought it was correct in VBA

I thought it would be something that bled over from another language.
 

Users who are viewing this thread

Back
Top Bottom