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

Insert multiple records between a date range

Hello,

New here - wondering if someone may be able to help me with an issue I'm having.

I have a table where I am recording details of shifts worked. Each record has the date of the shift, the start time, end time and other details. Most shifts are only one-offs so they can be entered individually, but every so often there is a series of them. I want to make it so that my user can enter the first date of the series, and the last date of the series, and for access to add records for each of the weekdays in between. I have created an unbound form to with 'startdate' and 'endate' fields as well as 'starttime' and 'endtime'

I found some code from a post on 'The Scripts' in 2006 (http://www.thescripts.com/forum/thread547400.html ) and have had a play with it but I can't get it to work - it adds the right number of records, but sets the date as back in 1899, rather than starting with the start date and ending with the end date.

If anyone could help me I'd really appreciate it.

Many thanks
Sep 23 '07 #1
3 4335
FishVal
2,653 Expert 2GB
Hi, AllyFrog.

The example converts integer number to date. This means adding the number of days to 30-Dec-1899.
I suggest you to use While cycle and DateAdd function to iterate dates in predefined range. Also check the syntax of SQL expression. Date constants has to be enclosed in # signs.
Sep 23 '07 #2
Hi, AllyFrog.

The example converts integer number to date. This means adding the number of days to 30-Dec-1899.
I suggest you to use While cycle and DateAdd function to iterate dates in predefined range. Also check the syntax of SQL expression. Date constants has to be enclosed in # signs.
Sorry to be a bother, but would you be able to give me an example (or point me to an example) of code using the While cycle and DateAdd function?
Sep 24 '07 #3
FishVal
2,653 Expert 2GB
Sorry to be a bother, but would you be able to give me an example (or point me to an example) of code using the While cycle and DateAdd function?
Hi, Ally. Sorry for delay.
The code will be something like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Ok_Click()
  2.  
  3.     Dim dteIterator As Date
  4.  
  5.     dteIterator = Me!StartDate
  6.  
  7.     While dteStart <= Me!EndDate
  8.         If Weekday(dteIterator, vbMonday) <> vbSaturday And _
  9.             Weekday(dteIterator, vbMonday) <> vbSunday Then
  10.             DoCmd.RunSQL "INSERT INTO Hours(Worker, Date, Time) VALUES ('" & _
  11.                 Me!Worker & "', #" & Format(dteIterator, "mm/dd/yyyy") & "#, 8);"
  12.         End If
  13.         dteIterator = DateAdd("d", 1, dteIterator)
  14.     Wend
  15.  
  16. End Sub
  17.  
Sep 25 '07 #4

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

Similar topics

0
by: jtocci | last post by:
I'm having a big problem with CREATE RULE...ON INSERT...INSERT INTO...SELECT...FROM...WHERE when I want to INSERT several (20~50) records based on a single INSERT to a view. Either I get a 'too...
3
by: arthur-e | last post by:
I can filter a query for a report on a field of a subform BUT now.... I'd like to be able to select more than one item in a multi-list box to select all the records. ALSO to use two fields (or...
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
4
by: Arpan | last post by:
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB" (datetime). Now when I am trying to add a new row using the...
2
by: chrisale | last post by:
Hi All, I've been racking my brain trying to figure out some sort of Sub-Select mySQL statement that will create a result with multiple rows of averaged values over a years time. What I have...
1
by: clayalphonso | last post by:
Here is the code: <% dim testArray, testArray2 dim Conn, rs dim sSQL, sConnString 'response.write request.form("sel1") 'testArray = split(request.form("sel1"),",") 'for each gidstuff In...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
1
by: RussCRM | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.