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

Create Records in Date Range (VBA)

Here is my problem. I have a lot of different fields that all revolve around two date fields, BeginDate and EndDate. The user enters information into both these fields along with other data. My problem is that I need the begin and endDates that they enter to be broken up by months. For example, if a user enters a begin date of 1/20/2009 and end date of 5/20/2009 access would automatically create 5 new records looking something like this (and duplicating the data in the other fields along with it):

BeginDate EndDate
1/20/2009 1/31/2009
2/1/2009 2/28/2009
3/1/2009 3/31/2009
4/1/2009 4/30/2009
5/1/2009 5/20/2009

Below is some logic that might be used to do this, I'm thinking a loop could be the answer but don't know exactly how to set it up in VBA... any help is appreciated!
Expand|Select|Wrap|Line Numbers
  1. Dim LngMTH as Long
  2. '1st record BeginDate as value
  3. LED=Dateserial(Year(BeginDate),Month(BeginDate)+1, 0) ' This gives the last day of the month.
  4. exit or goto
  5. LngMTH=Month(BeginDate)
  6. Do until LngMTH=Month(EndDate)+1
  7. BeginDate=Dateserial(Year(BeginDate),LngMTH,1)
  8. EndDate=Dateserial(Year(BeginDate),LngMTH+1,0)
  9. LngMTH=LngMTH+1
  10. Loop
  11. 'lastrecord
  12. BeginDate=Dateserial(Year(BeginDate),LngMTH,1)
  13. EndDate as given value
Jun 21 '09 #1
2 2672
NeoPa
32,556 Expert Mod 16PB
It seems you need to add in the part of the code that adds new records. Currently your pseudo-code loop does nothing other than process the loop.

Here is a link to basic DAO recordset processing (Basic DAO recordset loop using two recordsets). .AddNew() & .Update() are the methods you need to prepare and save the data.

Please have a go with this if you can. If you have further problems, please post the code you've attempted with any error messages and which lines they pertain to.

Welcome to Bytes!
Jun 22 '09 #2
ADezii
8,834 Expert 8TB
Just subscribing, as NePa has stated, let us know if you continue to have problems.
Jun 22 '09 #3

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

Similar topics

1
by: Manton | last post by:
Access 2000. I have a field in a table (tbl_data entry) which has a field called Free and another field called SD (containing 2 options: 5 and 6) The Free field is a yes/no format. I'd like to...
2
by: Rolan | last post by:
Can one set limits on html imported records in Access 97? For example, would like to prohibit importing records or a group of records whose ReferenceID number is not within an acceptable number...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
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...
5
by: jennwilson | last post by:
Using Access 2000 - I have a query that is suppose to return the records from table within specified time range and find matching data from another table . Table houses Clinician name, location...
4
Sandboxer
by: Sandboxer | last post by:
I want to be able to program Access to provide for me, by individual day, what my contract obligations are to my customers. Will Access recognize all the individual days in between a date range...
2
by: grego9 | last post by:
I have a problem in Excel 2000. I have written some VBA code that transfers data from the current excel workbook to a file called "Deal Input2.xls". Everything transfers ok apart from the date in...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.