473,395 Members | 1,678 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.

Unexplainable problem with date loop/ append query

365 100+
Still duin the holiday database...

and i have discovered something that i cant explain... can you guys?

ok i have a procedure which basically (quite a longwinded process) selects the start date and the enddate from a table by the ID and then in VB selects that start date and end date (as a date) and loops until sdt > edt this loop (basically) appends to another table information for each date sequentially until sdt > edt.

this works fine... however...

i stumbled on a situation whereby it doesnt...

if the start date and end date bridge new year (eg 31/12/07 - 7/01/08)
then rather than add a single day it adds a month....(01/01/08, 01/02/08, 01/03/08)

i have watched the process in debug mode and the variables are set correctly and increment, it seems for some reason that the query fails...
i do have variable written as # " sdt " # and like i say it does work normally and the vb is correct...

any one explain that one?
Dec 31 '07 #1
10 2055
jaxjagfan
254 Expert 100+
Still duin the holiday database...

and i have discovered something that i cant explain... can you guys?

ok i have a procedure which basically (quite a longwinded process) selects the start date and the enddate from a table by the ID and then in VB selects that start date and end date (as a date) and loops until sdt > edt this loop (basically) appends to another table information for each date sequentially until sdt > edt.

this works fine... however...

i stumbled on a situation whereby it doesnt...

if the start date and end date bridge new year (eg 31/12/07 - 7/01/08)
then rather than add a single day it adds a month....(01/01/08, 01/02/08, 01/03/08)

i have watched the process in debug mode and the variables are set correctly and increment, it seems for some reason that the query fails...
i do have variable written as # " sdt " # and like i say it does work normally and the vb is correct...

any one explain that one?
Expand|Select|Wrap|Line Numbers
  1. Dim sdt as Date
  2. Dim edt as Date
  3. Dim dtRun as Date
  4. Dim i as Integer
  5.  
  6. sdt = YourStartDate
  7. edt = YourEndDate 
  8. dtRun = sdt
  9. Do While dtRun <= edt
  10. "Do your appends and stuff"
  11. dtRun = DateAdd("d", 1, dtRun)
  12. Loop
  13.  
This will run thru a loop adding a day until the dtRun = edt. You can use the dtRun in your queries and it shouldn't matter if it crosses years between StartDate and EndDate.
Dec 31 '07 #2
missinglinq
3,532 Expert 2GB
When asking for help with code that is failing, it's a good idea to actually post your code!

Linq ;0)>
Jan 1 '08 #3
Dan2kx
365 100+
When asking for help with code that is failing, it's a good idea to actually post your code!

Linq ;0)>
well the actual code is quite long
i think i explained my problem quite well

but unfortunately jaxjagfan's solution doesnt solve the problem

so my code is basically (shortend of course)

Expand|Select|Wrap|Line Numbers
  1. dim sdt as date, edt as date, SDW as integer, MODD as integer
  2. blah blah 
  3.  
  4. sdt = dlookup
  5. edt = dlookup
  6. do until sdt > edt
  7. SWD = Weekday(sdt, vbMonday)
  8. If SWD < 6 Then
  9. CheckDateM = sdt - 2
  10. MODD = -1
  11. MODD = CheckDateM Mod 14
  12.  
  13.     select case modd
  14.     modd 0
  15.          sql update
  16.     modd 1
  17.          sql update 2
  18. ....................... Modd 2,3,4,7,8,9,10,
  19.     modd 11
  20.          sql update 11
  21.    end select
  22. end if
  23. sdt = sdt + 1 (also tried) sdt = dateadd("d",1,sdt)
  24. loop
  25.  
i have watched the code run in debug mode and it works and displays the new date sequencially as required... it just doesnt exist the same way in the table, (table field set to date/time obviously and input mask is shortdate)

I have the same routine bound to a form and instead of variables i am taking the date values from the form txtboxes and that works just fine, its strange.
this routine runs from a different form

if i use the dates 31/12/07 to 04/01/08
this is what gets inputted... 31/12/07, 01/01/08, 01/02/07, 01/03/07, 01/04/07
Jan 2 '08 #4
Dan2kx
365 100+
Any ideas?

Thanks
Jan 3 '08 #5
Dan2kx
365 100+
does anyone have any ideas?
Jan 4 '08 #6
Dan2kx
365 100+
Could it be because i am using in my append query the VB variable "AS Date" and then quoting it in the append query as #" & sdt & "# would it work if i quoted it as a string? '" & sdt & "'
Jan 6 '08 #7
MMcCarthy
14,534 Expert Mod 8TB
Could it be because i am using in my append query the VB variable "AS Date" and then quoting it in the append query as #" & sdt & "# would it work if i quoted it as a string? '" & sdt & "'
This may have something to do with the date format.

Have a look at this article.

Literal DateTimes and Their Delimiters (#)
Jan 8 '08 #8
Dan2kx
365 100+
I managed to solve it as such:

i set my sdt and edt variables and copied them as "Long"
in my append query i used rather than

#" & sdt & "#

i used

Format(" & sdt2 & ", 'dd/mm/yyyy')

if that makes sense
Jan 8 '08 #9
I have a feeling that your problem is that Microsoft database systems expect the date to be in an American format (mm/dd/yyyy) and you are using the British system (dd/mm/yyyy)
Jan 8 '08 #10
Dan2kx
365 100+
well it is weird, it works fine (the old way) except when you cross a new year (not sure about months... didnt check that out) but yeah that is probly the "main" reason (the problem only occured in queries), but hopefully i have fixed it, using a second variable as an integer (long) and then formatting that in the query!

Dan out
Jan 8 '08 #11

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

Similar topics

10
by: Colleyville Alan | last post by:
I am trying to turn a short and fat (63 columns) table into one that is tall and skinny (7 columns). Basically, I am trying to create a "reverse crosstab" using a looping structure in VBA along...
2
by: Charles Rouse | last post by:
How can I automatically add a weekly charge of $2.00 for each client in drug treatment? I have a "financial" table linked with the client table with 4 fields: clientID, date, charge, paid. Every...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
2
by: drdave | last post by:
Hi All, I'm filling an arraylist with other arraylists within a loop and within the first iteration and addition all is fine.. however when I clear my value holding temporary array I lose the...
8
by: luis | last post by:
Hi I'm using activestate python 2.4 on win xp 2 ed. and Ms Access 2002 (reading first http://starship.python.net/crew/bwilk/access.html) I have writed the following code def...
1
by: dick3425 | last post by:
How do I pass a date from a form to an append query in Access 2003 using DAO? I want to use a form and a combo box to choose the date and pass that date to an append query. The date field in the...
3
by: Bhavsan | last post by:
Here is what I am trying to do. Kindly, help me. 1. I'm creating a query dynamically based on User input using VBA (strSQL and DotSQL in the code below) 2. Executing the created query with in VBA...
3
by: alnug | last post by:
Hello, I'm trying to use the following code to read data from Excel files and put the data into an MS Access Table. Some of the Excel files have the tabs in the sequence Chart1, Sheet1, Sheet2 etc...
8
by: mvdave | last post by:
Hello all & I hope I'm posting in the right place.. I need to load a temporary table with a range of sequential dates, passing it a beginning and an end date from a criteria form. I have...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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...

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.