473,831 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(T otalHours([TimeFrom],[TimeTo]))
=TimeToSingle(B HolHours([dtmShiftDate],[timefrom],[timeto]))

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

=TimeToSingle(S aturdayHours([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 2723
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:

tblRatesByDayOf WeekOrHoliday:

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******** *************@g 44g2000cwa.goog legroups.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(T otalHours([TimeFrom],[TimeTo]))
=TimeToSingle(B HolHours([dtmShiftDate],[timefrom],[timeto]))

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

=TimeToSingle(S aturdayHours([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******** *************@o 13g2000cwo.goog legroups.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(p Date 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(dtmTempH ours, "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(dtmTempH ours, "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(va r1), "MM/DD/YY")
End If
'MsgBox var1

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

'Check whether a date is bank holiday, uses lookup from bank holiday
table
If DLookup("BankHo lidayDate", "tblBankHoliday ", "BankHolidayDat e = #" &
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
2489
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 Form_BeforeUpdate(Cancel As Integer) > > If Len(Nz(Me.CommDocNbrtxt, "")) = 0 Then > Me.CommDocNbrtxt.Value = GetDocIndex > End If The control isn't updated when I open the form and when I save the form I get a message that points to this code...
4
10367
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 that I am having is that sometimes the correct total shows up in print preview and sometimes it doesn't. Sometimes it is higher and sometimes it is lower (than the correct amount) and I cannot make any sense of the difference. The difference...
2
2707
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 requesting a "Replace" parameter. If the user clicks OK, the report opens, but only displays #Error. When the user tries to close the report, he is next presented with the choice of halting the code in break mode or not. Regardless of his choice, the app...
6
2282
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 Control Source property. I want to save them to a table so I can use them on a report. So the 2 questions are: 1. How do you use a calculated field that doesn't save to a table in a report?
5
18292
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 display the number of times a certain value appears in a certain field (i.e. perform a ‘count'). I will be doing this for many values in many fields so do not wish to have scores of queries to build my report.
3
1969
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 me give you a little background. this database is kind of like a human resources database. it collects info about people, where they work, and if they have any work-related issues where they work.
2
41671
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 a different sum aggregate query using the expression builder. When I select the query and it's single field, single row field it inserts the following in the control source box for the text box. =! I've tested the query (...
4
3164
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 further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
2
2112
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 =*. This works fine and I have all the correct values in the detail of the report. Now at the bottom of my report I want a total. I insert a text box in the report footer named Total and set the control source to =sum(). This does not work. I get...
0
9794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9319
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5623
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4420
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.