P
Piotr
Hi,
in following code I have problem as it doesnt execute for every sheet
in workbook ... i cant find the bug as it looks properly
Sub DAO_Import_planow_do_access()
' exports data from the active worksheet to a table in an Access
database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
Dim kanal As String
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Set db = OpenDatabase("D:\bazy\plany.mdb")
' open the database
Set rs = db.OpenRecordset("plany", dbOpenTable)
' get all records in a table
r = 1476 ' the start row in the worksheet
kanal = ActiveSheet.Name
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("brend") = Range("A" & r).Value
.Fields("group") = Range("B" & r).Value
.Fields("name") = Range("C" & r).Value
.Fields("quantity") = Range("D" & r).Value
.Fields("channel") = kanal
.Fields("month") = Range("F" & r).Value
.Fields("value") = Range("G" & r).Value
.Fields("file") = ActiveWorkbook.Name
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
Next WS
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
in following code I have problem as it doesnt execute for every sheet
in workbook ... i cant find the bug as it looks properly
Sub DAO_Import_planow_do_access()
' exports data from the active worksheet to a table in an Access
database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
Dim kanal As String
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Set db = OpenDatabase("D:\bazy\plany.mdb")
' open the database
Set rs = db.OpenRecordset("plany", dbOpenTable)
' get all records in a table
r = 1476 ' the start row in the worksheet
kanal = ActiveSheet.Name
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("brend") = Range("A" & r).Value
.Fields("group") = Range("B" & r).Value
.Fields("name") = Range("C" & r).Value
.Fields("quantity") = Range("D" & r).Value
.Fields("channel") = kanal
.Fields("month") = Range("F" & r).Value
.Fields("value") = Range("G" & r).Value
.Fields("file") = ActiveWorkbook.Name
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
Next WS
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub