473,396 Members | 1,987 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,396 software developers and data experts.

Excel to Access - code issue HELP!!

This code goes through 3 work sheets in the same XL workbook, day, eve and
night shift
in each sheet their are columns representing production work orders and
reject and downtime for each order
so in the tblproductiondetail there is one record for each work order and
many reject or downtime records (one to many)
code works fine to get a new record for each work order main info but when
creating the sub table related records for rejcts and downtime it writes the
same autonumber over and over again.

Public Sub dBSAVE()
DayShift
EveningShift
NightShift
End Sub

Sub NightShift()

Dim db As Database
Dim rs As Recordset
Sheets("Night Shift Report").Select
Dim col As Integer
Dim row As Integer
Dim inc As Integer
Dim prodcode As Long
Set db = OpenDatabase("S:\Production Database\ProductionData_tables.MDB")

For col = 2 To 17 Step 3
Sheets("Night Shift Report").Select

If Worksheets("Night Shift Report").Cells(10, col).Value = "" Then Exit
For

Set rs = db.OpenRecordset("tblProductionRunDetail")
Dim NightId As Long
With rs
.AddNew

rs(2) = ActiveSheet.Range("k3").Value 'date
rs(3) = ActiveSheet.Range("k4").Value 'supervisor
rs(4) = ActiveSheet.Range("h3").Value ' shift
rs(5) = ActiveSheet.Range("h4").Value ' time
rs(6) = Worksheets("Night Shift Report").Cells(10, col).Value
'product
rs(7) = Worksheets("Night Shift Report").Cells(14, col).Value ' good
rs(8) = Worksheets("Night Shift Report").Cells(64, col).Value ' bad
rs(9) = Worksheets("Night Shift Report").Cells(24, col).Value '
dryWt
rs(10) = Worksheets("Night Shift Report").Cells(23, col).Value '
wetwt
rs(11) = Worksheets("Night Shift Report").Cells(27, col).Value '
wttest
rs(12) = Worksheets("Night Shift Report").Cells(31, col).Value '
grosshours

.Update

End With
rs.MoveLast ' to get the autonumber field
NightId = rs(0)
rs.Close

'Rejects-------------------------------------------------------------

Set db = OpenDatabase("S:\Production
Database\ProductionData_tables.MDB")
Set rs = db.OpenRecordset("tblProductionRunRejects")
For row = 44 To 63 Step 1
If Worksheets(strSheet).Cells(row, col).Value = "" Then Exit For

rs.AddNew
rs(1) = NightId
rs(2) = Worksheets("Night Shift Report").Cells(row, col).Value
rs(3) = Worksheets("Night Shift Report").Cells(row, col + 1).Value
rs.Update
Next row
rs.Close

' Downtime-----------------------------------------------------------
Set db = OpenDatabase("S:\Production
Database\ProductionData_tables.MDB")
Set rs = db.OpenRecordset("tblProductionRunDownTime")
For row = 37 To 39 Step 1
If Worksheets("Night Shift Report").Cells(row, col).Value = "" Then
Exit For
rs.AddNew
rs(1) = NightId
rs(2) = Worksheets("Night Shift Report").Cells(row, col).Value
rs(3) = Worksheets("Night Shift Report").Cells(row, col + 1).Value
rs.Update
Next row
rs.Close

Next col
End Sub

Public Sub DayShift()

Dim db As Database
Dim rs As Recordset
Sheets("Day Shift Report").Select

Dim col As Integer
Dim row As Integer
Dim inc As Integer
Set db = OpenDatabase("S:\Production
Database\ProductionData_tables.MDB")

For col = 2 To 17 Step 3


Dim DayID As Long

If Worksheets("Day Shift Report").Cells(10, col).Value = "" Then Exit
For
Set rs = db.OpenRecordset("tblProductionRunDetail")

With rs
.AddNew

rs(2) = ActiveSheet.Range("k3").Value 'date
rs(3) = ActiveSheet.Range("k4").Value 'supervisor
rs(4) = ActiveSheet.Range("h3").Value ' shift
rs(5) = ActiveSheet.Range("h4").Value ' time
rs(6) = Worksheets("Day Shift Report").Cells(10, col).Value 'product
rs(7) = Worksheets("Day Shift Report").Cells(14, col).Value ' good
rs(8) = Worksheets("Day Shift Report").Cells(64, col).Value ' bad
rs(9) = Worksheets("Day Shift Report").Cells(24, col).Value ' dryWt
rs(10) = Worksheets("Day Shift Report").Cells(23, col).Value ' wetwt
rs(11) = Worksheets("Day Shift Report").Cells(27, col).Value '
wttest
rs(12) = Worksheets("Day Shift Report").Cells(31, col).Value '
grosshours

.Update
End With
rs.MoveFirst
rs.MoveLast
DayID = rs(0)
Debug.Print "DAY"; DayID; "RC"; rs.RecordCount

rs.Close

'Rejects-------------------------------------------------------------
Set rs = db.OpenRecordset("tblProductionRunRejects")
For row = 44 To 63 Step 1
If Worksheets("Day Shift Report").Cells(row, col).Value = "" Then
Exit For
rs.AddNew
rs(1) = DayID
rs(2) = Worksheets("Day Shift Report").Cells(row, col).Value
rs(3) = Worksheets("Day Shift Report").Cells(row, col + 1).Value
rs.Update
Next row
rs.Close

' Downtime-----------------------------------------------------------
Set db = OpenDatabase("S:\Production
Database\ProductionData_tables.MDB")
Set rs = db.OpenRecordset("tblProductionRunDownTime")
For row = 37 To 39 Step 1
If Worksheets("Day Shift Report").Cells(row, col).Value = "" Then Exit
For
rs.AddNew
rs(1) = DayID
rs(2) = Worksheets("Day Shift Report").Cells(row, col).Value
rs(3) = Worksheets("Day Shift Report").Cells(row, col + 1).Value
rs.Update
Next row
rs.Close
Next col
End Sub

Public Sub EveningShift()
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase("S:\Production Database\ProductionData_tables.MDB")

Dim strSheet As String

Sheets("Evening Shift Report").Select
strSheet = "Evening Shift Report"
Dim col As Integer
Dim row As Integer
Dim inc As Integer

For col = 2 To 17 Step 3

If Worksheets("Evening Shift Report").Cells(10, col).Value = "" Then
Exit For
Set rs = db.OpenRecordset("tblProductionRunDetail")

Dim Eveningid As Long

With rs
.AddNew

rs(2) = ActiveSheet.Range("k3").Value 'date
rs(3) = ActiveSheet.Range("k4").Value 'supervisor
rs(4) = ActiveSheet.Range("h3").Value ' shift
rs(5) = ActiveSheet.Range("h4").Value ' time
rs(6) = Worksheets("Evening Shift Report").Cells(10, col).Value
'product
rs(7) = Worksheets("Evening Shift Report").Cells(14, col).Value '
good
rs(8) = Worksheets("Evening Shift Report").Cells(64, col).Value '
bad
rs(9) = Worksheets("Evening Shift Report").Cells(24, col).Value '
dryWt
rs(10) = Worksheets("Evening Shift Report").Cells(23, col).Value '
wetwt
rs(11) = Worksheets("Evening Shift Report").Cells(27, col).Value '
wttest
rs(12) = Worksheets("Evening Shift Report").Cells(31, col).Value '
grosshours
.Update

End With
rs.MoveFirst
rs.MoveLast
Eveningid = rs(0)
Debug.Print "EVEn"; Eveningid; "RC"; rs.RecordCount
rs.Close

'Rejects-------------------------------------------------------------

Set db = OpenDatabase("S:\Production
Database\ProductionData_tables.MDB")
Set rs = db.OpenRecordset("tblProductionRunRejects")
For row = 44 To 63 Step 1
If Worksheets("Evening Shift Report").Cells(row, col).Value = "" Then
Exit For
rs.AddNew
rs(1) = Eveningid
rs(2) = Worksheets("Evening Shift Report").Cells(row, col).Value
rs(3) = Worksheets("Evening Shift Report").Cells(row, col + 1).Value
rs.Update
Next row
rs.Close

' Downtime-----------------------------------------------------------
Set db = OpenDatabase("S:\Production
Database\ProductionData_tables.MDB")
Set rs = db.OpenRecordset("tblProductionRunDownTime")
For row = 37 To 39 Step 1
If Worksheets("Evening Shift Report").Cells(row, col).Value = "" Then
Exit For
rs.AddNew
rs(1) = Eveningid
rs(2) = Worksheets("Evening Shift Report").Cells(row, col).Value
rs(3) = Worksheets("Evening Shift Report").Cells(row, col + 1).Value
rs.Update
Next row
rs.Close
Next col
End Sub

Nov 13 '05 #1
0 2831

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

Similar topics

1
by: Rocky A | last post by:
I need to open an excel workbook and import info to my access program. That isn't the problem, I've got the code down for doing what I want to do. I'm declaring the variable and setting it like...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
1
by: vadarv | last post by:
Hia! I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control. What I need to is to write to a table...
7
by: farhaaad | last post by:
Hi everybody, I just wanted to know if i can make a form in excel (the same as access forms), so when i enter data in excel form it goes to a table in access ? I mean when i enter a value in a...
1
by: eskelies | last post by:
Below you will find the code that I have written. I am asking it to search for an Excel file. Once it finds the correct dated Excel file it opens it. From there it is in search of information. I...
3
by: brenty66 | last post by:
I have a userform used as an interface to store information on excel spreadsheets. I have put a decent amount of work into it to this point and all of a sudden I am getting a catastrophic error...
4
by: MyWaterloo | last post by:
Hey all, I don't know where to go with this Excel question so I thought I would come here. You all have always been able to answer/help me with all my Access questions. I know this is not...
1
by: BhupendraNVyas | last post by:
Dear All, I want to send Out standing E-Mail detail to customer's throug ms access code .....can you help me for genrate a mail and attach a file from local hard disk drive. Regards, Bhupendra
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.