473,387 Members | 1,904 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.

Looping thru Table1 to parse records to Table2

I am still a beginner with VBA and I need the VBA Code for the
following problem.

I have a list of activities with their Scheduled Start date, Duration,
and Working hours in Table1.

I need to loop thru each record in Table1, split the long activity
durations according to their Working Hours shown in the Calendar field
and write these records to Table2.

For instance, if I have a 24 hours activity duration and my allowed
working hours are 5 days a week at 8 hours per day,
I would expect this activity to be ditributed over 3 days.

Source Table, Named : Table1

Activity Calendar Duration Craft Force Scheduled Start
A 5-8 24 PF 2 JUN 3 2005 7:00
B 7-24 48 EL 4 JUN 3 2005 7:00
C 6-12 6 MW 3 JUN 3 2005 7:00

Expected Table2.

Activity Calendar Duration Craft Force Scheduled Start

A 5-8 8 PF 2 JUN 3 2005 7:00
A 5-8 8 PF 2 JUN 6 2005 7:00
A 5-8 8 PF 2 JUN 7 2005 7:00
B 7-24 24 EL 4 JUN 3 2005 7:00
B 7-24 24 EL 4 JUN 4 2005 7:00
C 6-12 6 MW 3 JUN 3 2005 7:00
__________________________________________________ ____________
' The following code is my attempt at resolving this problem
Option Compare Database
Public Sub ActSplit()
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1
myRecordSet.Open

myRecordSet.MoveFirst

' Note Tables fields list in both tables :
' Activity, Calendar, Duration, Craft, Force, SchStart

Dim Dur as Integer 'Activity Duration
Dim Cal as String 'Activity Calendar
Dim WkDays as Integer 'Number of working Days per week
Dim WkHours as Integer 'Number of working Hours per Day
Dim Start as Date 'Original Scheduled Start Date
NewStart as Date 'New Start Dates

While Not myRecordSet.EOF
Dur = Duration
Cal = Calendar
Start = SchStart
NewDate = SchStart

Select Case Cal
Case "5-8"
WkDays = 5
WkHours = 8
Case "6-12"
WkDays = 6
WkHours = 12
Case "7-24"
WkDays = 7
WkHours = 24
End Select
If Dur > WkHours
For Dur = Duration To 0 Step - WkHours
' Skip Weekends
' Work starts on Friday on a 5 day week
If WeekDay(NewDate,2) = 5 and WkDays = 5
NewDate = NewStart+2
End If
' Skip Sundays
' Work starts on Friday on a 6 day week
If WeekDay(NewDate,2) = 6 and WkDays = 6
NewDate = NewStart+1
End If

If Dur > WkHours
NewDate = NewDate +1
Duration = WkHours
Dur = Dur - WkHours
Else 'Dur < ShiftHours
NewDate = NewDate +1
Duration = Dur
Dur = 0
Endif
SchStart = NewDate
'Syntax to Write record in Table2 ???
'Activity, Calendar, Duration, Craft, force, SchStart
Next

EndIf

myRecordSet.MoveNext
Wend

myRecordSet.Close
Set cnn1 = Nothing
Set myRecordSet = Nothing
End Sub

Thank you for your help

Wayne Collins

Nov 13 '05 #1
1 1961
I googled this:
http://www.georgehernandez.com/xData.../Recordset.htm
Syntax to edit a row:
Dim fieldName AS String
fieldName = "Duration"
myRecordSet(fieldName) = "24"

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JC-Atl | last post by:
I have 2 tables in a database: As an example, let's say Table1 has 20 rows, like this: Table1: CategoryNumber CategoryName 1000 Radios 1001 CD...
1
by: csgraham74 | last post by:
Hi guys, i have a little problem here. im attempting to write a stored procedure that compares two tables of the same data structure and adds (inserts) extra records that exist in table1 to...
0
by: Benoit | last post by:
Hello, I have problem to bind a combobox and a query with 2 tables. This a little code I Use : Dim myDR As SqlDataReader Dim myQuery As String = "Select Table2.IdSoc, Table2.Nom,...
0
by: Hetal | last post by:
Hi.. I am working on VB.NET 2003 (windows form) application and using ADO.NET to deal with databases. The table structure i am working with is as follows. DB1.Table1 (source)...
14
by: Yas | last post by:
Hello, I have 2 tables, Table1 and Table2. I have copied all data from Table1 to Table2. However Table1 is dynamic it has new rows added and some old rows modified everyday or every other...
3
by: Yas | last post by:
Hi everyone I am trying to create a DELETE Trigger. I have 2 tables. Table1 and Table2. Table 2 has all the same fields and records as Table1 + 1 extra column "date_removed" I would like that...
2
by: suren1503 | last post by:
Hi All Techies, I have created one DTS to copy table1 (which is on Oracle server) to table2 (on SQL Server 2000) I want to copy only new records + modified records from table1 to table2. I...
1
by: irinamas | last post by:
I have two tables: table1 with columns (ID, A1, A2) and table2 with columns (ID, newA1, newA2). I need to update values in table 1 with new values from table 2 only where IDs match. My query doesn't...
1
by: psyvanz | last post by:
i have created 2 tables name table1 and table2 with the same fieldnames in subjectnumber(sub-0001), subjectname(english1) but in my table2 i added studentnumber(s-0001) and studentname(paul) im...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.