473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with control source for text box on report

I want to use an expression as the control source for a text box in a
report (Access 2000).
Whilst I have sucessfully used these simple ones

=TimeToSingle(TotalHours([TimeFrom],[TimeTo]))
=TimeToSingle(BHolHours([dtmShiftDate],[timefrom],[timeto]))

I get problems when I include a text parameter Scale (control just
displays #error)

=TimeToSingle(SaturdayHours([dtmShiftDate],[timefrom],[timeto],[Scale]))

Where TotalHours, BHolHours and SaturdayHours are user defined
functions.

[Scale] is either null or has a value.
I tried forcing [Scale] to be an empty string (if scale is null)
without success.
If I change the parameter type in the function call to variant, the
parameter value is error 0 at run time (type mismatch).

The function runs fime if used to calculate the value as a calculated
column in a query.

Is this expression too complicated for a report field control source?

Nov 13 '05 #1
4 2685
Vivienne

Just off the top of my head, I've had problems with conflicts of control
name and field name, more on reports than on forms. That is, if you drag a
field from the field chooser thingy onto a report it is automatically given
the same name as the field. So then when you come to refer to it in an
expression you might be referring to the control, not a field in the table.
I often end up renaming the controls txtFieldName.

Have you tried just evaluating SaturdayHours in the debug window, to find
out if your problem is with the function, rather than the report? Oh ,sorry,
you've run it as a query.

SaturdayHours looks a bit numeric to me. Are you sure you wouldn't be better
forcing nulls to a numeric 0 rather than an empty string? Though I don't
know how SaturdayHours works. Or making the last argument optional?

By the way. The naming of the functions implies to me that you're writing
functions to account for different rates of pay for different 'special'
times of work. I'd try to get that sort of information into tables. If you
can:

tblRatesByDayOfWeekOrHoliday:

WorkDate Rate
Monday 1.0
..
..
Friday 1.0
Saturday 1.5
Sunday 1.5
BH 2.0
XmasDay 2.0
NYDay 2.0

Then some function, highestRate (workDate) that for any day finds what the
highest rate is for that particular date.

Then your calculating function calls highestRate x hoursWorked. Or
something.

Of course you will need a table of bank holidays (or dates that you pay at
the bank holiday rate). But the rest can be got from the date.

Mike

"VivN" <vi*****************@whnt.nhs.uk> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I want to use an expression as the control source for a text box in a
report (Access 2000).
Whilst I have sucessfully used these simple ones

=TimeToSingle(TotalHours([TimeFrom],[TimeTo]))
=TimeToSingle(BHolHours([dtmShiftDate],[timefrom],[timeto]))

I get problems when I include a text parameter Scale (control just
displays #error)

=TimeToSingle(SaturdayHours([dtmShiftDate],[timefrom],[timeto],[Scale]))

Where TotalHours, BHolHours and SaturdayHours are user defined
functions.

[Scale] is either null or has a value.
I tried forcing [Scale] to be an empty string (if scale is null)
without success.
If I change the parameter type in the function call to variant, the
parameter value is error 0 at run time (type mismatch).

The function runs fime if used to calculate the value as a calculated
column in a query.

Is this expression too complicated for a report field control source?

Nov 13 '05 #2
Mike
I thought the naming conflict was a winner - but the this is not the
solution.
I have had problems in the past in Access 97 where a string
concatenation expression worked happily in a query but not for the
calculated field in a report.
I think it could be to do with the string argument not getting properly
formatted, but find it impossible to debug a function call made this
way - breakpoints and message boxes don't get fired.

I don't have the option of a table lookup - this report goes to payroll
who work out the fees - I just have to work out how many hours each
person worked in each category (weekday, sat, sun, unsocial, bank
holiday).

Vivn

Nov 13 '05 #3

"VivN" <vi*****************@whnt.nhs.uk> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Mike
I thought the naming conflict was a winner - but the this is not the
solution.
I have had problems in the past in Access 97 where a string
concatenation expression worked happily in a query but not for the
calculated field in a report.
I think it could be to do with the string argument not getting properly
formatted, but find it impossible to debug a function call made this
way - breakpoints and message boxes don't get fired.
What's the code for your 4 functions then?

And I assume that 3 of the parameters are datetime, what type is Scale?

I'll try it here.
I don't have the option of a table lookup - this report goes to payroll
who work out the fees - I just have to work out how many hours each
person worked in each category (weekday, sat, sun, unsocial, bank
holiday).


Sure. Not for fees maybe, but you seem to have 3 functions that are doing
different things based upon the day of week of holiday type. In which case
are you feeding data in manually? That's what I meant and wrap those 3
functions into one, Access can work out the DOW and a short table of BH etc.
could catch exceptions. But I'm only guessing, I don't really know how it's
being called.

Mike
Nov 13 '05 #4
OK here it is -
SaturdayHours works out hours worked on a saturday, uses IsBHol also
listed below.
As you will see, there is a table to hold bank hol days for look up
purposes.
The database is used to book staff into shifts (these do not have fixed
start/end times)
Admin person then records if each person worked that shift, then prints
the report to send to payroll.
Staff who are in charge get an enhanced rate, this is different from
the rate that their staff grade normally gets.
All rather complicated..

VivN

@@@@@@@@@@@@@@@@@@@@@@@
Public Function SaturdayHours(pDate As Date, pStart As Date, pEnd As
Date, pScale As Variant) As Date
'Work outs saturday hours
dtmTempHours = 0
If pDate < #1/10/2004# And pScale = "NHZZ" Then
SaturdayHours = Format(dtmTempHours, "hh:mm")
Exit Function
End If
'Work out if night shift - covers two days
If pStart > pEnd Then
'Covers two days
If Weekday(pDate) = vbSaturday And Not IsBHol(pDate) Then
'Midnight - pStart = saturday hours
dtmTempHours = 24 - pStart
Else
If Weekday(pDate + 1) = vbSaturday And Not IsBHol(pDate + 1)
Then
dtmTempHours = pEnd
End If
End If
Else
'one day
If Weekday(pDate) = vbSaturday And Not IsBHol(pDate) Then
dtmTempHours = pEnd - pStart
End If
End If
SaturdayHours = Format(dtmTempHours, "hh:mm")
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@
Public Function IsBHol(pDate As Date) As Boolean
'This chunk of code was put in because of the problem caused by Bank
Holidays
'not being recognised. This was due to the computer puttting any low
dates into
'American date format.

'================================
Dim var1 As Variant 'DATE
Dim var2, var3, var4 As Variant

var1 = CStr(pDate)
If Left(var1, 2) <= "12" Then
var2 = Left(var1, 3)
var3 = Mid(var1, 4, 3)
var4 = Right(var1, 2)
var1 = var3 & var2 & var4
var1 = CDate(var1)
Else
var2 = Left(var1, 3)
var3 = Mid(var1, 4, 3)
var4 = Right(var1, 2)
var1 = var3 & var2 & var4
var1 = Format(CDate(var1), "MM/DD/YY")
End If
'MsgBox var1

'================================

'Check whether a date is bank holiday, uses lookup from bank holiday
table
If DLookup("BankHolidayDate", "tblBankHoliday", "BankHolidayDate = #" &
var1 & "#") Then
IsBHol = True
Else
IsBHol = False
End If
End Function

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Tony Williams | last post by:
I have a module called GetDocIndex which calculates a sequential number in a control called CommDocNbrtxt. On the BeforeUpdate property of the form I have the following code Private Sub...
4
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
2
by: Sharon | last post by:
I've had an Access 2000 app running successfully for many months on both Windows XP and Windows 2000. Recently when my Windows 2000 users call a particular report, they get first a dialog...
6
by: Mark Lees | last post by:
I've created some fields that calculate future dates. The way they are set up they do not save to a table. This is the expression I used (=DateSerial(Year(),Month()+6,Day(). I placed it in the...
5
by: Cro | last post by:
Hello Access Developers, I'd like to know if it is possible to perform a count in an expression that defines a control source. My report is based on a query. In my report, I want a text box to...
3
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
2
by: Bob | last post by:
I've got a bound report with a query as the record source. I'm adding a total to the footer and have inserted a text box to display it. I'm attempting to set the control source of the text box to...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: bobw2961 | last post by:
I have what I hope is a simple question for some of you. I have two fields. Quantity and Price. I enter a text box named SubTotal in the detail of the report and set the control source to =*. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.