for...next loop within a while loop.

C

Chieko Kuroda

Hello,
I am trying to automate a pretty simple task.
I'm trying to end an automatic population of bound text boxes when the
for...next loop gets to a certain time. I have two unbound text boxes,
startTime([txtfirstAppt]), and endTime([txtLastAppt]) and 16 bound text
boxes half are starttime and the other half are endtime. So far, I have been
able to populate all of the controls with the correct times, but I can't
figure out how to stop the population when the curtime value is equal to the
unbound endtime control value. Would anybody help me?
Thanks
Chieko


Private Sub txtLastAppt_LostFocus()
Dim INTNUM As Integer, curtime As Date

curtime = [txtfirstAppt].Value

For INTNUM = 1 To 8

Me.Controls("timeofAppointment" & INTNUM).Value = curtime
Me.Controls("EndofAppointment" & INTNUM).Value = curtime + 0.0416666
'fraction of 1 day or =1/24hr.
If Me.Controls("timeofAppointment" & INTNUM).Value = "12:00:00 pm"
Then
Me.Controls("EndofAppointment" & INTNUM).Value = curtime + 0.083333
'fraction of 1 day or = 2/24.
curtime = curtime + 0.0416666
End If

'set the rest of the fields to null if you reach the last appointment
time.

curtime = curtime + 0.0416666


Next INTNUM

End Sub
 
M

Marshall Barton

Add an If statement as shown below.
--
Marsh
MVP [MS Access]


Chieko said:
Hello,
I am trying to automate a pretty simple task.
I'm trying to end an automatic population of bound text boxes when the
for...next loop gets to a certain time. I have two unbound text boxes,
startTime([txtfirstAppt]), and endTime([txtLastAppt]) and 16 bound text
boxes half are starttime and the other half are endtime. So far, I have been
able to populate all of the controls with the correct times, but I can't
figure out how to stop the population when the curtime value is equal to the
unbound endtime control value. Would anybody help me?
Thanks
Chieko


Private Sub txtLastAppt_LostFocus()
Dim INTNUM As Integer, curtime As Date

curtime = [txtfirstAppt].Value

For INTNUM = 1 To 8

Me.Controls("timeofAppointment" & INTNUM).Value = curtime
Me.Controls("EndofAppointment" & INTNUM).Value = curtime + 0.0416666
'fraction of 1 day or =1/24hr.
If Me.Controls("timeofAppointment" & INTNUM).Value = "12:00:00 pm"
Then
Me.Controls("EndofAppointment" & INTNUM).Value = curtime + 0.083333
'fraction of 1 day or = 2/24.
curtime = curtime + 0.0416666
End If

'set the rest of the fields to null if you reach the last appointment
time.

curtime = curtime + 0.0416666

If curtime >= [txtEndAppt] Then Exit For
 

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