What am I doing wrong???

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

Guest

Hi all

This is the code I have on the exit event of a field - [fldTimeDF]

Private Sub fldTimeDF_Exit(Cancel As Integer)
If [fldPriority] = "High" Then
[fldDeadlineTime] = DateAdd("n", [UrgHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadlineFixedTime] = True Then
[fldDeadlineTime] = [fldUniqueTimeToReturn]
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadline] = True Then
[fldDeadlineTime] = DateAdd("n", [UHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldPriority] = "Normal" Then
Select Case [fldTimeDF]
Case [fldTimeDF] >= [fldDeadLineStart1], Is <= [fldDeadlineEnd1]
[fldDeadlineTime] = [fldDeadlineTime1]
[fldDeadlineDate] = [fldDateDF]
Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
[fldDeadlineTime] = [fldDeadlineTime2]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])
If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
Case [fldTimeDF] >= [fldDeadLineStart3], Is >= [fldDeadlineEnd3]
[fldDeadlineTime] = [fldDeadlineTime3]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])

If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
End Select

End If
End Sub


I am having a real problem with the last two case statements - and
specifically the If statement that tests whether the day of the week is a 1
or a 7 . The way the code is working at the moment is that it is adding the
3 days regardless of whether or not the weekday is a 1 or a 7.

Can I not do an If within a Select Case? If not how do I get the select to
check the day of the week as well as the other conditions?

Please Help!!
 
If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If

try

If [DayOfWeek] = "1" Or [DayOfWeek] = "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If

hth
 
I would expect [DayOfWeek] to be numeric, not text. If this is the case,
use:
If [DayOfWeek] = 1 Or [DayOfWeek] = 7 Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
--
Duane Hookom
MS Access MVP


tina said:
If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If

try

If [DayOfWeek] = "1" Or [DayOfWeek] = "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If

hth


Cadburys said:
Hi all

This is the code I have on the exit event of a field - [fldTimeDF]

Private Sub fldTimeDF_Exit(Cancel As Integer)
If [fldPriority] = "High" Then
[fldDeadlineTime] = DateAdd("n", [UrgHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadlineFixedTime] = True Then
[fldDeadlineTime] = [fldUniqueTimeToReturn]
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadline] = True Then
[fldDeadlineTime] = DateAdd("n", [UHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldPriority] = "Normal" Then
Select Case [fldTimeDF]
Case [fldTimeDF] >= [fldDeadLineStart1], Is <= [fldDeadlineEnd1]
[fldDeadlineTime] = [fldDeadlineTime1]
[fldDeadlineDate] = [fldDateDF]
Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
[fldDeadlineTime] = [fldDeadlineTime2]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])
If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
Case [fldTimeDF] >= [fldDeadLineStart3], Is >= [fldDeadlineEnd3]
[fldDeadlineTime] = [fldDeadlineTime3]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])

If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
End Select

End If
End Sub


I am having a real problem with the last two case statements - and
specifically the If statement that tests whether the day of the week is a 1
or a 7 . The way the code is working at the moment is that it is adding the
3 days regardless of whether or not the weekday is a 1 or a 7.

Can I not do an If within a Select Case? If not how do I get the select
to
check the day of the week as well as the other conditions?

Please Help!!
 
Tina and Duane

Thank you for your responses. I changed the day of the week to find the
number 1 or 7 and it worked for that. But I am still not getting the correct
answer when the last 4 cases are met. My code now looks like this:

'Return Deadline Date and Deadline Time

Private Sub fldTimeDF_Exit(Cancel As Integer)

If [fldPriority] = "High" Then 'if priority is high then
[fldDeadlineTime] = DateAdd("n", [UrgHtoADDinMin], [fldTimeDF]) 'Add
number of minutes to the Digital File Date
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same as the
Digital File Date
ElseIf [fldUniqueDeadlineFixedTime] = True Then ' If client has a fixed
time deadline then
[fldDeadlineTime] = [fldUniqueTimeToReturn] ' Enter the fixed
deadline into the Deadline Time field
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same as the
Digital File Date
ElseIf [fldUniqueDeadline] = True Then 'if Client has a unique number of
hours deadline
[fldDeadlineTime] = DateAdd("n", [UHtoADDinMin], [fldTimeDF]) ' Add
number of minutes of deadline to Digital File Date
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same as the
Digital File Date

ElseIf [fldPriority] = "Normal" Then 'if priority is normal then

Select Case [fldTimeDF]

Case [fldTimeDF] >= [fldDeadLineStart1], Is <= [fldDeadlineEnd1]
'Digital File Time is greater than or equal to 9.01 and less than or equal
to 12.30
[fldDeadlineTime] = [fldDeadlineTime1] ' Deadline Time is
17.00
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same
as the Digital File Date

Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
And [DayOfWeek] <> 6 'Digital File Time is greater than or equal to 12.31 and
less than or equal to 17.30 and Digital File Date does not fall on a Friday
or Saturday
[fldDeadlineTime] = [fldDeadlineTime2] ' Deadline Time is
10.30
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF]) 'Deadline
Date is Digital File Date plus 1 day

Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
And [DayOfWeek] = 6 'Digital File Time is greater than or equal to 12.31
and less than or equal to 17.30 and Digital File Date does fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime2] ' Deadline Time is 10.30
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF]) 'Deadline
Date is Digital File Date plus 3 days, to take to following Monday

Case [fldTimeDF] >= [fldDeadLineStart3], Is <= [fldDeadlineEnd3]
And [DayOfWeek] <> 6 'Digital File Time is greater than or equal to 17.31 and
less than or equal to 23.59 and Digital File Date does not fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3] 'Deadline Time is 13.00
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF]) 'Deadline
Date is Digital File Date plus 1 day

Case [fldTimeDF] >= [fldDeadLineStart3], Is <= [fldDeadlineEnd3]
And [DayOfWeek] = 6 'Digital File Time is greater than or equal to 17.31 and
less than or equal to 23.59 and Digital File Date does fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3] 'Deadline Time is
13.00
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF]) 'Deadline
Date is Digital File Date plus 3 days, to take to following Monday

Case [fldTimeDF] <= [fldDeadLineStart3a], Is <=
[fldDeadlineEnd3a] And [DayOfWeek] <> 6 'Digital File Time is greater than or
equal to 00.01 and less than or equal to 09.00 and Digital File Date does not
fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3a] ' Deadline Time is
13.00
[fldDeadlineDate] = [fldDateDF] 'Deadline Date is same os
Digital File Date

Case [fldTimeDF] <= [fldDeadLineStart3a], Is <=
[fldDeadlineEnd3a] And [DayOfWeek] = 6 'Digital File Time is greater than or
equal to 00.01 and less than or equal to 07.00 and Digital File Date does
fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3a] ' Deadline Time is
13.00
[fldDeadlineDate] = DateAdd("d", 2, [fldDateDF]) ' Deadline
Date is Digital File Date plus 2 days, to take to following Monday

End Select


End If

End Sub

In the first Case
If the fldTimeDF is 09:53 and the fldDateDF is 17/05/2006
then the correct deadline date of 17/05/2006
the correct deadline time of 17.00 is returned

In the Second Case
If the fldTimeDF is 14:02 and the fldDateDF is 17/05/2006
then the correct deadline date of 18/05/2006
the correct deadline time of 10:30 is returned

In the Remaining Cases
- These seem to be getting ignored. as I keep getting the 10:30 deadline time
If the fldTimeDF is 17:38 it should return as deadline time 0f 13:00 for the
next day.

I have checked and rechecked that I am using the correct operators and the
correct field names etc. but I just cant seem to figure out why these last
statements are getting ignored.

Please help if you can.
--
Cheers


Cadburys said:
Hi all

This is the code I have on the exit event of a field - [fldTimeDF]

Private Sub fldTimeDF_Exit(Cancel As Integer)
If [fldPriority] = "High" Then
[fldDeadlineTime] = DateAdd("n", [UrgHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadlineFixedTime] = True Then
[fldDeadlineTime] = [fldUniqueTimeToReturn]
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadline] = True Then
[fldDeadlineTime] = DateAdd("n", [UHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldPriority] = "Normal" Then
Select Case [fldTimeDF]
Case [fldTimeDF] >= [fldDeadLineStart1], Is <= [fldDeadlineEnd1]
[fldDeadlineTime] = [fldDeadlineTime1]
[fldDeadlineDate] = [fldDateDF]
Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
[fldDeadlineTime] = [fldDeadlineTime2]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])
If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
Case [fldTimeDF] >= [fldDeadLineStart3], Is >= [fldDeadlineEnd3]
[fldDeadlineTime] = [fldDeadlineTime3]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])

If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
End Select

End If
End Sub


I am having a real problem with the last two case statements - and
specifically the If statement that tests whether the day of the week is a 1
or a 7 . The way the code is working at the moment is that it is adding the
3 days regardless of whether or not the weekday is a 1 or a 7.

Can I not do an If within a Select Case? If not how do I get the select to
check the day of the week as well as the other conditions?

Please Help!!
 
I think you need to look up Select Case in Help. For instance
Select Case [fldTimeDF]
Case [fldTimeDF] >= [fldDeadLineStart1], Is <= [fldDeadlineEnd1]
Why do you have [fldTimeDF] listed after the "Case ". It looks like you are
testing for a true value.

I would expect to see something like:
Select Case [fldTimeDF]
Case is >= [fldDeadLineStart1], Is <= [fldDeadlineEnd1]

--
Duane Hookom
MS Access MVP


Cadburys said:
Tina and Duane

Thank you for your responses. I changed the day of the week to find the
number 1 or 7 and it worked for that. But I am still not getting the
correct
answer when the last 4 cases are met. My code now looks like this:

'Return Deadline Date and Deadline Time

Private Sub fldTimeDF_Exit(Cancel As Integer)

If [fldPriority] = "High" Then 'if priority is high then
[fldDeadlineTime] = DateAdd("n", [UrgHtoADDinMin], [fldTimeDF])
'Add
number of minutes to the Digital File Date
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same as the
Digital File Date
ElseIf [fldUniqueDeadlineFixedTime] = True Then ' If client has a fixed
time deadline then
[fldDeadlineTime] = [fldUniqueTimeToReturn] ' Enter the fixed
deadline into the Deadline Time field
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same as the
Digital File Date
ElseIf [fldUniqueDeadline] = True Then 'if Client has a unique number
of
hours deadline
[fldDeadlineTime] = DateAdd("n", [UHtoADDinMin], [fldTimeDF]) ' Add
number of minutes of deadline to Digital File Date
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same as the
Digital File Date

ElseIf [fldPriority] = "Normal" Then 'if priority is normal then

Select Case [fldTimeDF]

Case [fldTimeDF] >= [fldDeadLineStart1], Is <=
[fldDeadlineEnd1]
'Digital File Time is greater than or equal to 9.01 and less than or equal
to 12.30
[fldDeadlineTime] = [fldDeadlineTime1] ' Deadline Time is
17.00
[fldDeadlineDate] = [fldDateDF] ' Deadline Date is the same
as the Digital File Date

Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
And [DayOfWeek] <> 6 'Digital File Time is greater than or equal to 12.31
and
less than or equal to 17.30 and Digital File Date does not fall on a
Friday
or Saturday
[fldDeadlineTime] = [fldDeadlineTime2] ' Deadline Time is
10.30
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF]) 'Deadline
Date is Digital File Date plus 1 day

Case [fldTimeDF] >= [fldDeadLineStart2], Is <= [fldDeadlineEnd2]
And [DayOfWeek] = 6 'Digital File Time is greater than or equal to 12.31
and less than or equal to 17.30 and Digital File Date does fall on a
Friday
[fldDeadlineTime] = [fldDeadlineTime2] ' Deadline Time is
10.30
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF]) 'Deadline
Date is Digital File Date plus 3 days, to take to following Monday

Case [fldTimeDF] >= [fldDeadLineStart3], Is <=
[fldDeadlineEnd3]
And [DayOfWeek] <> 6 'Digital File Time is greater than or equal to 17.31
and
less than or equal to 23.59 and Digital File Date does not fall on a
Friday
[fldDeadlineTime] = [fldDeadlineTime3] 'Deadline Time is
13.00
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF]) 'Deadline
Date is Digital File Date plus 1 day

Case [fldTimeDF] >= [fldDeadLineStart3], Is <=
[fldDeadlineEnd3]
And [DayOfWeek] = 6 'Digital File Time is greater than or equal to 17.31
and
less than or equal to 23.59 and Digital File Date does fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3] 'Deadline Time is
13.00
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF]) 'Deadline
Date is Digital File Date plus 3 days, to take to following Monday

Case [fldTimeDF] <= [fldDeadLineStart3a], Is <=
[fldDeadlineEnd3a] And [DayOfWeek] <> 6 'Digital File Time is greater than
or
equal to 00.01 and less than or equal to 09.00 and Digital File Date does
not
fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3a] ' Deadline Time is
13.00
[fldDeadlineDate] = [fldDateDF] 'Deadline Date is same os
Digital File Date

Case [fldTimeDF] <= [fldDeadLineStart3a], Is <=
[fldDeadlineEnd3a] And [DayOfWeek] = 6 'Digital File Time is greater than
or
equal to 00.01 and less than or equal to 07.00 and Digital File Date does
fall on a Friday
[fldDeadlineTime] = [fldDeadlineTime3a] ' Deadline Time is
13.00
[fldDeadlineDate] = DateAdd("d", 2, [fldDateDF]) '
Deadline
Date is Digital File Date plus 2 days, to take to following Monday

End Select


End If

End Sub

In the first Case
If the fldTimeDF is 09:53 and the fldDateDF is 17/05/2006
then the correct deadline date of 17/05/2006
the correct deadline time of 17.00 is returned

In the Second Case
If the fldTimeDF is 14:02 and the fldDateDF is 17/05/2006
then the correct deadline date of 18/05/2006
the correct deadline time of 10:30 is returned

In the Remaining Cases
- These seem to be getting ignored. as I keep getting the 10:30 deadline
time
If the fldTimeDF is 17:38 it should return as deadline time 0f 13:00 for
the
next day.

I have checked and rechecked that I am using the correct operators and the
correct field names etc. but I just cant seem to figure out why these
last
statements are getting ignored.

Please help if you can.
--
Cheers


Cadburys said:
Hi all

This is the code I have on the exit event of a field - [fldTimeDF]

Private Sub fldTimeDF_Exit(Cancel As Integer)
If [fldPriority] = "High" Then
[fldDeadlineTime] = DateAdd("n", [UrgHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadlineFixedTime] = True Then
[fldDeadlineTime] = [fldUniqueTimeToReturn]
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldUniqueDeadline] = True Then
[fldDeadlineTime] = DateAdd("n", [UHtoADDinMin], [fldTimeDF])
[fldDeadlineDate] = [fldDateDF]
ElseIf [fldPriority] = "Normal" Then
Select Case [fldTimeDF]
Case [fldTimeDF] >= [fldDeadLineStart1], Is <=
[fldDeadlineEnd1]
[fldDeadlineTime] = [fldDeadlineTime1]
[fldDeadlineDate] = [fldDateDF]
Case [fldTimeDF] >= [fldDeadLineStart2], Is <=
[fldDeadlineEnd2]
[fldDeadlineTime] = [fldDeadlineTime2]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])
If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
Case [fldTimeDF] >= [fldDeadLineStart3], Is >=
[fldDeadlineEnd3]
[fldDeadlineTime] = [fldDeadlineTime3]
[fldDeadlineDate] = DateAdd("d", 1, [fldDateDF])

If [DayOfWeek] = "1" Or "7" Then
[fldDeadlineDate] = DateAdd("d", 3, [fldDateDF])
End If
End Select

End If
End Sub


I am having a real problem with the last two case statements - and
specifically the If statement that tests whether the day of the week is a
1
or a 7 . The way the code is working at the moment is that it is adding
the
3 days regardless of whether or not the weekday is a 1 or a 7.

Can I not do an If within a Select Case? If not how do I get the select
to
check the day of the week as well as the other conditions?

Please Help!!
 

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