I inherited a database that contains three fields:
- OR Time (a number)
- OR Time In Room (Date/Time)
- OR Time Out Room (Date/Time)
On the form is an unbounded field that correctly calculates and displays the minutes between the patient's entering the OR room and leaving the room (using DateDiff with the minutes option, 'n'). The "OR Time" field in every record in the database is blank.
I want to calculate that time difference based on any change to either of the Date/Time fields and store it in the field "OR Time". The department now wants a report that sums "OR Time"s on a monthly basis, and I don't want to waste time re-calculating this field everytime the report is run. I have set the field "OR Time" to Locked in preparation for making this work.
I haven't been able to figure out the syntax, however, to make this happen. I created the following public function to call "After Update" for either of the "room" fields: - Public Function Calculate_Minutes(Date1 As Date, Date2 As Date) As Number
-
Calculate_Minutes = DateDiff("n", Date1, Date2)
-
End Function
-
but the error I get is "Compile error. User-defined type not defined." pointing to the function's declaration statement.
The call looks like this: - Private Sub OR_Time_Out_Room_AfterUpdate()
-
Me.[OR Time] = Calculate_Minutes(Me.OR_Time_In_Room, Me.OR_Time_Out_Room)
-
End Sub
-
and generates no error of its own.
What am I doing wrong?
The problem is with the Return Type of the Function, namely Number. There is no Data Type named Number. To play it safe, redefine your Data Type: - Public Function Calculate_Minutes(Date1 As Date, Date2 As Date) As Long
8 2488
The problem is with the Return Type of the Function, namely Number. There is no Data Type named Number. To play it safe, redefine your Data Type: - Public Function Calculate_Minutes(Date1 As Date, Date2 As Date) As Long
Okay, that makes sense. I thought "Number" was odd for a datatype, but I didn't get an error within the code window itself, so I thought it was okay.
So I fixed up all that (and the calls were a little wonky, too, it turns out), but I'm getting this from the public function:
"Reserved error (-1517); there is no message from this error"
which leaves me a little stumped as to where to go from here. Here's the function as it stands: - Public Function Calculate_Minutes(Date1 As Date, Date2 As Date) As Long
-
On Error GoTo Err_Calculate_Minutes
-
-
Calculate_Minutes = DateDiff("n", Date1, Date2)
-
-
Exit_Calculate_Minutes:
-
Exit Function
-
-
Err_Calculate_Minutes:
-
MsgBox Err.Description
-
Resume Exit_Calculate_Minutes
-
-
End Function
-
and the call from one of the fields: - Private Sub OR_Time_In_Room_AfterUpdate()
-
On Error GoTo Err_OR_Time_In_Room_AfterUpdate
-
-
Me.[OR Time] = Calculate_Minutes(Me.OR_Time_In_Room, Me.OR_Time_Out_Room)
-
-
Exit_OR_Time_In_Room_AfterUpdate:
-
Exit Sub
-
-
Err_OR_Time_In_Room_AfterUpdate:
-
MsgBox Err.Description
-
Resume Exit_OR_Time_In_Room_AfterUpdate
-
-
End Sub
It appears that it should work now, sueb, and I'm not really sure why it doesn't. If you wish to Attach the Front End, I'll be happy to look at it. I still have an Archived copy of the Back End, and I'm assuming that it is still applicable. If you do Attach the FE, please indicate what Form is the one in question.
I came in this morning and tried it again, right before getting ready to upload a copy, and it does work now.
It's not the first time that I've experienced that: I work on a bit of code for several hours into the evening; it looks like it should work but doesn't; I go home, come back, and just fire it off again in the morning, and it works.
Mystifying.
So, thanks again for steering me onto the path of righteousness, ADezii!
NeoPa 32,556
Expert Mod 16PB
Sue, what you are suggesting (and now have working it appears) is exactly the sort of thing that we try to warn developers away from. This is de-normalising your data and is generally considered a very bad idea. The concepts behind normalisation, and why it is so important, are covered in Database Normalisation and Table structures. I highly recommend reading it, and reverting your database back to a more normalised form.
NeoPa, I realize that this is a little unorthodox, and at some point I'll probably re-work it. For now, I'm just going to leave it as is. I'm not even sure that the user's requirements around this issue are settled yet.
But thanks for the link--it's always good to have references handy!
NeoPa 32,556
Expert Mod 16PB
Not my recomendation clearly, but as long as you're making an informed choice on the matter I can relax knowing I've done what I need to. I also understand, of course, the restrictions imposed when working on inherited databases. Always more tricky than ones you've designed yourself.
Good luck with your project :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jochen scheire |
last post by:
Is there a way I can calculate a field in a form based on another field in
the same form. When clicking submit, both values should be posted to the
next page. I want to be able to type in a value...
|
by: carla |
last post by:
I am using Access 2000 and have a table, tblCurrent. That table
contains several fields - three of those fields are ,
and . What I want to accomplish in my data entry form, is
first entering the...
|
by: Shawn Yates |
last post by:
I have query which shows when employees clock in (long time) and clock
out(long time). To find the total hours worked in hours and minutes I
have another field on my query with the following:
...
|
by: SpyderSL |
last post by:
Hey,
I have created an access form, in which I have a drop down with employee names.
These are the steps I would like to happen:
1. A user will enter a number in FIELD A
2. The user will...
|
by: Michelle Anderson |
last post by:
I have an access form. In the form, it co ntains 3 fields : Type, hours, and Amount.
Field "Type" is a combo box and it contains 2 values: Standard and Rush
Field " Hours" is just a numeric...
|
by: CSmith |
last post by:
I have a calculated field in a query, it calculates the # of days an employee has been employed using the following statement =datediff("d", , NOW()) by default. When an employee is terminated, I...
|
by: compl |
last post by:
I have a database that I need to restrict the ability to edit one
field based on another. The two fields are DOS (date) and Amount
(currency). I only want the users to be able to edit the Amount...
|
by: whamo |
last post by:
I have the need to populate a field based on the selection in a combo box.
Starting out simple. (2) tables tbl_OSE_Info and tbl_Input;
tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
|
by: Shortstuff12345 |
last post by:
I'm trying to use VBA code to disable a field based on the value of another field in a form. The code I have properly updates the enabled property of the field when it changes; however, it changes...
|
by: MNNovice |
last post by:
Calculate net amount based on conditions
________________________________________
I need to calculate a net amount that is based on FedRatio. Normally the FedRatio is set to be 80% but there are a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
| |