if statements and variables

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

Guest

hi i am using this if statement at the min:

stDateType = Appointmentdate

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take 5 patients"

this works fine what i was hoping to do was replace the number of patients
with a value entered by the user

eg. "you can only take" , monday, "patients
is this possible hoe do i set up the monday variable ?
any help would be gret thanks

yours

david
 
Not enough info to give a specific answer. If the user would enter it from
the form, then you need only a text box to accept the value. We will call it
txtMaxPatients.

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take " & Me.txtMaxPatients & " patients"

In reality, this is probably entered at some point in time to set up
recurring info, so you would need a table that would have every working day
in the table with the day of the week and the max number of patients.

intMaxPatients = DLookup("[Week_Day]", "MaxAppts", _
"[Week_Day] = " & Weekday(Appointmentdate, vbMonday))
MsbBox "You can only take " & Cstr(intMaxPatients) & " patients"

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take 5 patients"

This is untested code, so you may need to twik it.
 
i have a table named days with Monday as a field im using the code you gave me:

intMaxPatients = DLookup("[Monday]", "days", _
"[Monday] = " & Weekday(Appointmentdate, vbMonday))
MsbBox "You can only take " & Cstr(intMaxPatients) & " patients"

it returns a msg box saying " invalid use of null " im not sure what this
means can any one tell me

thanks david

Klatuu said:
Not enough info to give a specific answer. If the user would enter it from
the form, then you need only a text box to accept the value. We will call it
txtMaxPatients.

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take " & Me.txtMaxPatients & " patients"

In reality, this is probably entered at some point in time to set up
recurring info, so you would need a table that would have every working day
in the table with the day of the week and the max number of patients.

intMaxPatients = DLookup("[Week_Day]", "MaxAppts", _
"[Week_Day] = " & Weekday(Appointmentdate, vbMonday))
MsbBox "You can only take " & Cstr(intMaxPatients) & " patients"

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take 5 patients"

This is untested code, so you may need to twik it.


DAVIDPEOVER said:
hi i am using this if statement at the min:

stDateType = Appointmentdate

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take 5 patients"

this works fine what i was hoping to do was replace the number of patients
with a value entered by the user

eg. "you can only take" , monday, "patients
is this possible hoe do i set up the monday variable ?
any help would be gret thanks

yours

david
 
The Weekday function does not return a string, it returns an integer. If
your [Monday] field is an interger, the only problem is the syntax of your
query. I also don't know how you structured your table. I am a little
suspicious when I see a field named [Monday]. Here is how I would suggest
the table be structured:

[Week_Day] [Max_Patients]
Integer Integer
1 5 'Monday
2 20
3 20
4 25
5 20
6 0
7 0 'Sunday

That would be the entire table. Now the corrected version of the code I
sent will work (I tested it)

intMaxPatients = DLookup("[Max_Patients]","days","[Week_Day] = " & _
cstr(Weekday(date(),vbMonday)))

intMaxPatients now contains the maximum number of appointments available for
the day. I don't know how you are determining how many appointments have
been set for the day, but this is what you would compare it against.

DAVIDPEOVER said:
i have a table named days with Monday as a field im using the code you gave me:

intMaxPatients = DLookup("[Monday]", "days", _
"[Monday] = " & Weekday(Appointmentdate, vbMonday))
MsbBox "You can only take " & Cstr(intMaxPatients) & " patients"

it returns a msg box saying " invalid use of null " im not sure what this
means can any one tell me

thanks david

Klatuu said:
Not enough info to give a specific answer. If the user would enter it from
the form, then you need only a text box to accept the value. We will call it
txtMaxPatients.

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take " & Me.txtMaxPatients & " patients"

In reality, this is probably entered at some point in time to set up
recurring info, so you would need a table that would have every working day
in the table with the day of the week and the max number of patients.

intMaxPatients = DLookup("[Week_Day]", "MaxAppts", _
"[Week_Day] = " & Weekday(Appointmentdate, vbMonday))
MsbBox "You can only take " & Cstr(intMaxPatients) & " patients"

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take 5 patients"

This is untested code, so you may need to twik it.


DAVIDPEOVER said:
hi i am using this if statement at the min:

stDateType = Appointmentdate

If Weekday(Appointmentdate, vbMonday) = vbMonday Then
MsgBox "you can only take 5 patients"

this works fine what i was hoping to do was replace the number of patients
with a value entered by the user

eg. "you can only take" , monday, "patients
is this possible hoe do i set up the monday variable ?
any help would be gret thanks

yours

david
 
Back
Top