Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 20th, 2008, 10:20 AM
gabjosh7 gabjosh7 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 3 gabjosh7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 5 sec
Reputation Power: 0
MS Access - replicate records in a database

I have a table that lists an event with a start date and an end date as one record. I need to replicate the record for the number of days between start and end.

Reply With Quote
  #2  
Old November 20th, 2008, 12:05 PM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information
 
Join Date: Apr 2008
Posts: 404 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 19 h 50 m 9 sec
Reputation Power: 2
Is it the EXACT SAME data every time or does something change?

Are you looking for a query or is VBA code OK?
__________________
P.S. I am looking for work. <grin>.

Reply With Quote
  #3  
Old November 20th, 2008, 12:44 PM
gabjosh7 gabjosh7 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 3 gabjosh7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by dykebert
Is it the EXACT SAME data every time or does something change?

Are you looking for a query or is VBA code OK?


It will different data every time. I would prefer a query but I can't figure out how to replicate the record.

Reply With Quote
  #4  
Old November 20th, 2008, 05:39 PM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information
 
Join Date: Apr 2008
Posts: 404 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 19 h 50 m 9 sec
Reputation Power: 2
Sorry I guess I wasn't clear.

My question is are the duplicate records exactly the same as the original or do you need some sort of different data?

Also if the start date is 11/4/2008 and the end date is 11/10/2008 do you want to add 5 or 6 records or some other number of records?

Reply With Quote
  #5  
Old November 21st, 2008, 06:49 AM
gabjosh7 gabjosh7 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 3 gabjosh7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by dykebert
Sorry I guess I wasn't clear.

My question is are the duplicate records exactly the same as the original or do you need some sort of different data?

Also if the start date is 11/4/2008 and the end date is 11/10/2008 do you want to add 5 or 6 records or some other number of records?


Except for the start date the data in the fields of the record would be exactly the same. I need the start date to ascend 1 for each day. If the start date is 11/4/2008 and the end date is 11/10/2008 then I would need to add 6 records as 1 already exists. I can write something to change the start dates for the new records. Thanks.

Reply With Quote
  #6  
Old November 24th, 2008, 11:34 AM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information
 
Join Date: Apr 2008
Posts: 404 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 19 h 50 m 9 sec
Reputation Power: 2
OK here's the basic code for what you want.
Code:
    Dim connDB As ADODB.Connection
    Dim miscRS As New ADODB.Recordset
    Dim qry As New Command
    Dim sql As String
    Dim fulSQL As String
    
    Dim ndx As Integer
    Dim startDT As Date
    Dim dtCnt As Integer
    
    
    Set connDB = CurrentProject.Connection
    
    Set qry.ActiveConnection = connDB

    sql = "SELECT * FROM <tblName> "
    
    miscRS.Open sql, connDB, adOpenStatic
    
    sql = "INSERT INTO <tblName> (<field1Name>, <field2Name>, <StartDateField>) VALUES ("
    
    Do While Not miscRS.EOF
    
        startDT = Miscrs!<startDateField>
        dtCnt = DateDiff("d", startDT, miscRS!<endDateField>)
        
        For ndx = 1 To dtCnt
            fullsql = sql & Miscrs!<field1Name> & "," & miscrs!<field2Name> & ",#" & dateAdd("d",ndx,startDT) & "#)"
            qry.CommandText = fullsql
            qry.Execute
        Next
        
        miscRS.MoveNext
    Loop
    
    miscRS.Close
    connDB.Close
    Set qry = Nothing
    Set connDB = Nothing


You will need to replace <name> with the appropriate name from your application.

If you need to run this more than once, you will need to add some sort of WHERE clause to the first sql statement to get only the new records you want processed.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > MS Access - replicate records in a database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT