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
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 427 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 2 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
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 427 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 2 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
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 427 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 2 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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek