473,395 Members | 1,554 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,395 software developers and data experts.

dcont within a loop returning error

Hi all im struggling with this and some help would be great.
overview: ive written a workshop time and attendance program and all works great however my boss has found that when doing a wages print out to show in and out times for the week some staff arrive early for the shift and remain on idle time until after shift starts, thus they get paid too much time, so i decided to write a function that will run when loading the wages section before displaying, it will basically check clock in time against shift start time and then write the correct time in a new field, this will only happen if the staff member has not clocked onto a job before shift starts allowing for genuine overtime to be paid.
to do this i created a query to work within the dates we are dealing with and the clocking types involed, the basic update works ok with a loop but when i tried to ensure the genuine early clockings are retained i used a dcount to find if that staff member had infact clocked onto a job before shift start.
here is my code
Expand|Select|Wrap|Line Numbers
  1. Public Function fixt()
  2. Dim Rst As DAO.Recordset
  3. Set Rst = CurrentDb.OpenRecordset("timefix")
  4. With Rst
  5. DoCmd.SetWarnings False
  6. Do Until .EOF
  7. Dim strSQLall As String
  8. Dim newtime As String
  9. newtime = "#08:30#"
  10.  
  11. If Rst![2ndtime] < "08:30:00" And Rst![ctype] = 5 Then
  12. Dim goodtime As Integer
  13. goodtime = Nz(DCount("ID", "timefix", "[2ndtime] < ""08:30:00"" AND [ctech] = " & Rst![ctech] & " AND [ctype] = 1"), 0)
  14. If goodtime <> 0 Then
  15.    strSQLall = "UPDATE [timefix] SET [newon] = """ & Rst![2ndtime] & """"
  16. strSQLall = strSQLall & " WHERE [ID]  = " & Rst![ID] & ";"
  17. DoCmd.RunSQL (strSQLall)
  18. End If
  19. Else
  20.  strSQLall = "UPDATE [timefix] SET [newon] = " & newtime & ""
  21. strSQLall = strSQLall & " WHERE [ID]  = " & Rst![ID] & ";"
  22. DoCmd.RunSQL (strSQLall)
  23. End If
  24. If Rst![2ndtime] >= "08:30:00" Then
  25.  
  26.    strSQLall = "UPDATE [timefix] SET [newon] = """ & Rst![2ndtime] & """"
  27. strSQLall = strSQLall & " WHERE [ID]  = " & Rst![ID] & ";"
  28. DoCmd.RunSQL (strSQLall)
  29.  
  30. End If
  31.  
  32. .MoveNext
  33. Loop
  34. End With
  35. End Function
the bit thats causing the error is the goodtime im wondering if its because its inside a loop but i cant see why i wouldent work unless its some querky access thing, i know ive got lots more coding to do to get this right for a weeks worth across ten staff but until i get past this i cant move forward.
Thanks in advance
Nick
p.s the only time it runs ok is if i remove the [ctype] and [2ndtime] expressions from the dcount.
Jun 15 '12 #1

✓ answered by Rabbit

Well there's your problem.

This is a string.
Expand|Select|Wrap|Line Numbers
  1. "12/31/2012"
This is a date.
Expand|Select|Wrap|Line Numbers
  1. #12/31/2012"
The same thing applies to time values.

9 1385
Rabbit
12,516 Expert Mod 8TB
You haven't said what the error is.
Jun 15 '12 #2
error is 3464 data type mismatch in criteria expression
Jun 15 '12 #3
Perhaps someone could suggest a better way of achieving what i need.
so working with a single table that consists of date, techid, type of clocking, on time and off time + edited ontime and edited off time (not entire list or actual field names)
i need to do the following.
For selected date range i.e between 01/01/2012 and 08/01/2012 loop through all records and where the type of clocking = 5 check if its before 08:30 and if it is see if the same tech has a clocking type of 1 that that starts before 08:30 if so copy stat time to edited on time and if not set edited on time to 08:30.
i will also need to do simular for off times but one step at a time.
any suggestions welcomes as my brain is now well and truly pickled.
thanks Nick
Jun 15 '12 #4
Rabbit
12,516 Expert Mod 8TB
The error message is pretty clear. There's a data type mismatch. So what are the data types of the fields?
Jun 16 '12 #5
Expand|Select|Wrap|Line Numbers
  1. goodtime = Nz(DCount("ID", "timefix", "[2ndtime] < ""08:30:00"" AND [ctech] = " & Rst![ctech] & " AND [ctype] = 1"), 0)
id is autonumber, 2ndtime is long time, ctech is number, ctype is number.
Jun 16 '12 #6
Rabbit
12,516 Expert Mod 8TB
Well there's your problem.

This is a string.
Expand|Select|Wrap|Line Numbers
  1. "12/31/2012"
This is a date.
Expand|Select|Wrap|Line Numbers
  1. #12/31/2012"
The same thing applies to time values.
Jun 16 '12 #7
AH ha, flaming quotes lol i thought i needed a hash and as you can see i used them in the code above newtime = "#08:30#"
but i was using two hashes so i will try your method and let you know.
thanks
Rabbit
Jun 17 '12 #8
Thanks for that it helped a lot as my mind was pickled, in fact i had tried that earlier on but as always with dates and times was unsure, but once i had that corrected i found a further error which was that i had in fact set [ctech] in the table to a Text field (doh) why the hell would i want a text field to store technician id's . well its getting there now and after that i have to alter the master table and correct any issues from the text field in the rest of the code.
Thanks again :-)
Jun 17 '12 #9
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Jun 18 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: matt breedlove | last post by:
(x-posted to microsoft.public.dotnet.general and microsoft.public.dotnet.languages.vb) Hello all. I am currently creating a Windows Service using VB.NET and would like to return an error if...
5
by: Mark Oueis | last post by:
I've been struggling with this question for a while. What is better design? To design functions to return error codes when an error occures, or to have them throw exceptions. If you chose the...
3
by: deko | last post by:
I have a logging routine that's supposed to silently log errors caught by error handler code on certain functions. The problem is sometimes stuff happens and the error handler can get caught in a...
3
by: Simon Jefferies | last post by:
Hello, I've created a fresh VB.NET Setup project using the wizard. When I build the project I get the following error message: ERROR: An error occurred while validating. HRESULT = '80004002'...
4
by: clayne | last post by:
I realize this may work for the majority of platforms. But I am concerned about the aspects of sign extension and portability. Is this portable: { unsigned long bw; if ((signed long)(bw...
70
by: junky_fellow | last post by:
Guys, If main() calls some function func() and that function returns the error (errno), then does it make sense to return that value (errno) from main. (in case main can't proceed further) ? ...
1
by: david.katkowski | last post by:
I'm trying to use the __builtin__ filter function within a class; however, I receive the following error: NameError: global name 'MajEthnic' is not defined The line of code is: EthMaj =...
20
by: Constantine AI | last post by:
Hi I have this code which i thought was perfect maybe a bit of a mess but it works. The only problem is that the rst!PONo does not look at the table properly and generate a continuing number, which i...
2
by: FutureShock | last post by:
I am using a registration class to process a registration form and need some opinions on returning error messages. I am self referring the page on submit. I would like to send each form field...
3
by: Paulo Santos | last post by:
First of all, it's my first time here. Also, i'm working on a simple rent management program for a school project. I've fixed most of the errors but i'm lost on what could be wrong here: error:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
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
tracyyun
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...
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,...

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.