473,903 Members | 4,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Connectio n
Set cnn1 = CurrentProject. Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.Act iveConnection = cnn1
myRecordSet.Ope n

myRecordSet.Mov eFirst

' 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.Mov eNext
Wend

myRecordSet.Clo se
Set cnn1 = Nothing
Set myRecordSet = Nothing
End Sub

Thank you for your help

Wayne Collins

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

Nov 13 '05 #2

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

Similar topics

0
1238
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 Players .... ... 1019 Older Electronics
1
1549
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 table2. My problem is that i dont have a unique identifier between the tables.
0
1085
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, Table1.IdListingP From Table1, Table2 where
0
1161
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) ================ ID Name
14
6998
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 day... How can I continue to keep Table2 up to date without always having to copy everything from Table1? Basically from now on I would only like to copy new rows or modified
3
3923
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 when a record is deleted from Table 1, the trigger finds that record in Table2 and updates the date_removed filed with current time stamp. The primary key on both is combination of domain,admin_group and cn.
2
1670
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 would appreciate the help. Thanks, Suren...
1
1699
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 work even for one column: update table1b set b.A1= (select a.newA1 from table 2 a where a.ID=b.ID) Inner query returns multiple records, and the whole thing doesn't work. Any suggestions? Thanks.
1
4286
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 using dataenvironment in connecting my (table1) ms access 2007 database in a datagrid but my problem is how to save and add all information bind(table1) in datagrid into another database table2 in my ms access, i want to connect what is inside my...
0
11291
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10988
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10504
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4312
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3327
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.