Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Len, Val(Mid)

Status
Not open for further replies.

spartansFC

Programmer
Apr 1, 2009
165
0
0
GB
thread702-1705763

Hi

the above thread was closed and I think Duane mentioned that there would be a problem when some dates that have 1 or 2 characters at the start.

Fees_Summary_pjweeq.jpg


On the attached image i'm having problems showing the correct values as some dates have 1 character and some have 2 at the very beginning of the string, the problem only happens on the 2nd week of each month, I've worked out the other days using:

Code:
=IIf(Len([11])=11,Val(Mid([11],4,2)),IIf(Len([11])=12,Val(Mid([11],4,2)),IIf(Len([11])=13,Val(Mid([11],5,2)),Val(Mid([11],3,2)))))

It also only happens when the string count is 12 in the 2nd week, the count of children on each day (in blue) is calculated using:

Code:
Val: Max(Day([TheDate])) & Chr(13) & Chr(10) & Abs(Sum([strSessionDayCount]="X")) & Chr(13) & Chr(10) & Max([strSessionGrp]) & Chr(13) & Chr(10) & Min([IsHoliday])

on the 8 April, based off the above, the values are:

8 chr13 Chr 10 (3)
25 chr13 chr 10 (4)
X chr13 chr 10 (3)
-1 (2) the minus 1 is because this day is a school holiday

this shows the number of children "25" correctly using Val(Mid([11],4,2)

but for the 10 June, the values in the field are:

10 chr 13 chr10 (4)
27 chr 13 chr10 (4)
X chr 13 chr10 (3)
0 (1)

this shows the number of children "7" incorrectly, the Val that I should be using Val(Mid([11],5,2)

I'm not sure how I change the code so that if the string count = 12 but the date is only 1 character to use: Val(Mid([11],4,2) or when
the string count = 12 and the date has 2 characters to use Val(Mid([11],5,2)

I thought about using the LEFT and LEN together so the new statement would have 5 conditions but i'm not sure if you can combine them in that way:

IIf(Len([11])=11,Val(Mid([11],4,2))
IIF(LEFT([11)=1 and LEN([11)=12,Val(Mid([11],4,2))
IIF(LEFT([11)=2 and LEN([11)=12,Val(Mid([11],5,2))
IIf(Len([11])=13,Val(Mid([11],5,2))
Val(Mid([11],3,2)

Thanks

Mikie
 
I'm not sure of all the logic and conditions but I am sure that I would create a small user-defined function that would accept the needed values and return exactly what is needed. Combining multiple expressions/calculations can more easily be managed in code where you can add comments, use If/End If, use Select Case, and re-use again and again while maintaining in one module.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top