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

Inserting multiple rows based on a Date range

5
Hi Bytes,

Using a previous question as a base Access 2000 Inserting multiple rows based on a date range.
I also wanted to insert multiple rows into a table according to a date range supplied by a user (eg txtRDateStart & txtRDateEnd). The script was envisaged to be able to also gather a time and text description that would be repeated within each row.

For example:
The user would enter...
Start Date: 13/03/2010
End Date: 17/03/2010
Time: 12:00
Description: "Check Mail"

click 'OK'...
Thereby resulting in 5 new rows added to a table 'tblReminders' into columns RDate, RTime & RDescription such as...

13/03/2010, 12:00, Check mail
14/03/2010, 12:00, Check Mail
15/03/2010, 12:00, Check Mail
16/03/2010, 12:00, Check Mail
17/03/2010, 12:00, Check Mail

Using the code provided by PEB in Access 2000 Inserting multiple rows based on a date range

I ended up with the below that is working however the Date being returnned is always the '30/12/1899'.
I understand this is probably due to the way dates are configured in Access and the use of 'Int' in the below code, so I changed to table's RDate field format from short date to nothing and I seem to be getting a time value returning, e.g. for 13/03/2010 the return is 12:03:21 AM. - when I format this to a 'Short Date I again get '30/12/1899'.
Expand|Select|Wrap|Line Numbers
  1. Dim RepeatEvent
  2.  
  3. For RepeatEvent = Int(CDate(Me!txtRDateStart)) To Int(CDate(Me!txtRDateEnd))
  4.  
  5. DoCmd.RunSQL "INSERT INTO tblReminder (RDescription, RDate, RTime) " & _
  6.              "SELECT Forms![frmReminder_New]!txtRDescription AS Expr1," & _
  7.              Format$(RepeatEvent, "dd/mm/yyyy") & _
  8.              ", [Forms]![frmReminder_New]![txtRTime] AS Expr3;"
  9.  
  10. Next RepeatEvent
Any help would be greatly appreciated.
Mar 13 '10 #1

✓ answered by NeoPa

Your problem is a lack of delimiters around your date data. It is literal data (rather than a reference) so must be delimited if string or Date/Time (See Literal DateTimes and Their Delimiters (#) and Quotes (') and Double-Quotes (") - Where and When to use them).

It's not clear from this, what type of field [RDate] is in tblReminder. I would guess it's actually a string, but it may conceivably be a Date/Time.

If it's a string then your lines #7 through #9 should be :
Expand|Select|Wrap|Line Numbers
  1.              "SELECT Forms![frmReminder_New]!txtRDescription AS Expr1,'" & _
  2.              Format$(RepeatEvent, "dd/mm/yyyy") & _
  3.              "', [Forms]![frmReminder_New]![txtRTime] AS Expr3;"
If it's a date then they should be :
Expand|Select|Wrap|Line Numbers
  1.              "SELECT Forms![frmReminder_New]!txtRDescription AS Expr1,#" & _
  2.              Format$(RepeatEvent, "m/d/yyyy") & _
  3.              "#, [Forms]![frmReminder_New]![txtRTime] AS Expr3;"
NB. It doesn't matter where you're from. m/d/yyyy is always correct for SQL literal dates.

3 4979
NeoPa
32,556 Expert Mod 16PB
Your problem is a lack of delimiters around your date data. It is literal data (rather than a reference) so must be delimited if string or Date/Time (See Literal DateTimes and Their Delimiters (#) and Quotes (') and Double-Quotes (") - Where and When to use them).

It's not clear from this, what type of field [RDate] is in tblReminder. I would guess it's actually a string, but it may conceivably be a Date/Time.

If it's a string then your lines #7 through #9 should be :
Expand|Select|Wrap|Line Numbers
  1.              "SELECT Forms![frmReminder_New]!txtRDescription AS Expr1,'" & _
  2.              Format$(RepeatEvent, "dd/mm/yyyy") & _
  3.              "', [Forms]![frmReminder_New]![txtRTime] AS Expr3;"
If it's a date then they should be :
Expand|Select|Wrap|Line Numbers
  1.              "SELECT Forms![frmReminder_New]!txtRDescription AS Expr1,#" & _
  2.              Format$(RepeatEvent, "m/d/yyyy") & _
  3.              "#, [Forms]![frmReminder_New]![txtRTime] AS Expr3;"
NB. It doesn't matter where you're from. m/d/yyyy is always correct for SQL literal dates.
Mar 13 '10 #2
Vinda
5
NeoPa that has worked like a charm, thankyou so very much.
My field within tblReminder is a date field and so inserting the '#'s was spot on.
Thanks again, I very much appreciate your time.
Cheers,
Vince
Mar 14 '10 #3
NeoPa
32,556 Expert Mod 16PB
Happy to help Vince :)
Mar 15 '10 #4

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

Similar topics

20
by: WindAndWaves | last post by:
Hi Gurus I was wondering if you can send me in the right direction: I have a table with about 300 rows. I want to make all of them invisible and when a user enters a code in a form then make...
16
by: Tim Davidge | last post by:
Hi folks, been a while since I have posted a plea for help and I think I have forgotten everything I learnt from the helpful contributors to this newsgroup, that said however : I'm trying to...
0
by: B | last post by:
Using Access2000, the sample code below is what I have been modifying and working on since the past week and I could not get it to work properly. What I wanted to accomplish: 1) read from a...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
15
by: Jaraba | last post by:
I am working in a project that I need to parse an arrayt an select records based upon the values parsed. I used the functions developed by Knut Stolze in his article 'Parsing Strings'. I am...
4
by: Joanie | last post by:
I have a form that records dates of unavailability for a worker. Based on what is entered in the simple table behind the form, many calculations take place to create employee "load" balance. Each...
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...
0
by: c0dergirl | last post by:
This c# program allows you to select multiple items from a listbox. For each selected item, a worksheet is created in the workbook with some information. Right now I create a chart that plots some...
0
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined...
1
by: evenlater | last post by:
I have an Excel workbook that I'm programming from Access. The rows in the workbook vary in height. So let's say row 8 is taller than the rows above it. If I *manually* insert 2 new rows at the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
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
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...

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.