can you have nested if statments

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i want to be able to ask is it a monday and is it before 12 noon i am
currently using the following code to tell the user how many patients they
can book in for each day

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
intMaxPatients = DLookup("[Monday]", "[days]")
MsgBox "You can only take " & (intMaxPatients) & " patients"

i was hoping to add to this to be able to say X ammount of patients in the
morning and Y ammount of patients in the afternoon.

is it possible to do this? any help would be greatly recieved

yours david
 
David,

Yes you can have nested If statements.

If x=y Then
If a=2 Then
If abc=xyz Then
If DaffyDuck = 12 Then
'Do something
ElseIf DaffyDuck = 123 Then
'Do something else
ElseIf DaffyDuck = "dead" Then
'Do something
Else
'Don't do anything
End If
Else
'- - -
End If
End If
End If


Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
thats great thanks

Graham R Seach said:
David,

Yes you can have nested If statements.

If x=y Then
If a=2 Then
If abc=xyz Then
If DaffyDuck = 12 Then
'Do something
ElseIf DaffyDuck = 123 Then
'Do something else
ElseIf DaffyDuck = "dead" Then
'Do something
Else
'Don't do anything
End If
Else
'- - -
End If
End If
End If


Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

DAVIDPEOVER said:
i want to be able to ask is it a monday and is it before 12 noon i am
currently using the following code to tell the user how many patients they
can book in for each day

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
intMaxPatients = DLookup("[Monday]", "[days]")
MsgBox "You can only take " & (intMaxPatients) & " patients"

i was hoping to add to this to be able to say X ammount of patients in the
morning and Y ammount of patients in the afternoon.

is it possible to do this? any help would be greatly recieved

yours david
 
i want to be able to ask is it a monday and is it before 12 noon i am
currently using the following code to tell the user how many patients they
can book in for each day

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
intMaxPatients = DLookup("[Monday]", "[days]")
MsgBox "You can only take " & (intMaxPatients) & " patients"

Just a comment - if you have fields named Monday, Tuesday, etc. in
your table, you might want to reconsider your table design. Storing
data in fieldnames is Bad Design!

If instead you had a table with fields PatientDay (values 1 = Monday,
2 = Tuesday, etc.) and Patients, you could have one *record* per day
and be able to use a single dlookup:

intMaxPatients = DLookUp("[Patients]", "[days]", "[PatientDay] = " &
Weekday([AppointmentDate, vbMonday)

with no IF statements at all - and perhaps no code at all, as you
could do this in a Query.

John W. Vinson[MVP]
 

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

Back
Top