specialfreckles
asked on
VB5 Excel sheet to Access or Jet -Important-
Ok Experts-
I have a program in VB5 that logs data once a minute to a spreadsheet.
I would like to archive it to Jet once a day
The workbook name is "Today.xls"
The sheetname is format$(now, "mmm dd yyyy")
Row 2 holds the 00:01 readings
Row 62 holds the 01:01 readings and so on to Row 1441
At midnight the last history worksheet is moved in front of worksheets(1) and the sheet I want becomes worksheets(2)
My declares are:
Dim m_App As New Excel.Application
Dim m_WB As Workbook ''Active Workbook for this excel instance
Dim m_WS As Worksheet "Active Worksheet
const WBfileName = App.Path + "\WB\Today.xls"
I always store string data in columns A - J. If the channel for that column isn't being used I stuff a default string and set the colwidth to 0.
Row 1 is always a heading row for the A-J columns
The row number is always (the minutes passed in the day) + 1
The sheetname is always the date.
I know nothing about Jet or Access.
How can I create and maintain a database that will let me compare strings from any 2 dates in its history?
Can someone provide a starter routine or give me link that gets me on top of it.
-Thanks
I have a program in VB5 that logs data once a minute to a spreadsheet.
I would like to archive it to Jet once a day
The workbook name is "Today.xls"
The sheetname is format$(now, "mmm dd yyyy")
Row 2 holds the 00:01 readings
Row 62 holds the 01:01 readings and so on to Row 1441
At midnight the last history worksheet is moved in front of worksheets(1) and the sheet I want becomes worksheets(2)
My declares are:
Dim m_App As New Excel.Application
Dim m_WB As Workbook ''Active Workbook for this excel instance
Dim m_WS As Worksheet "Active Worksheet
const WBfileName = App.Path + "\WB\Today.xls"
I always store string data in columns A - J. If the channel for that column isn't being used I stuff a default string and set the colwidth to 0.
Row 1 is always a heading row for the A-J columns
The row number is always (the minutes passed in the day) + 1
The sheetname is always the date.
I know nothing about Jet or Access.
How can I create and maintain a database that will let me compare strings from any 2 dates in its history?
Can someone provide a starter routine or give me link that gets me on top of it.
-Thanks
ASKER
>How can I create and maintain a database that will let me compare strings from any 2 dates in its history?
>Can someone provide a starter routine or give me link that gets me on top of it.
Thanks fo the input supunt but I need to export worksheets(2).range("A1:J1 441") to Jet or access, with range("A1:J1") being the headings, the row (- 1) is already the time of day and the sheet name is already the date.
>Can someone provide a starter routine or give me link that gets me on top of it.
Thanks fo the input supunt but I need to export worksheets(2).range("A1:J1
OK, here we go...add a button and a label to your form.
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Long
Dim j As Long
Dim strLine As String
Dim sql As String
Dim tblName As String
On Error GoTo SaveErr
Dim m_App As New Excel.Application
'Dim m_WB As Workbook 'Active Workbook for this excel instance
'Dim m_WS As Worksheet 'Active Worksheet
Dim WBfileName As String
WBfileName = App.Path & "\test.xls" ' + "\WB\Today.xls"
If m_App Is Nothing Then Exit Sub ' application did not get created
m_App.Workbooks.Open FileName:=WBfileName
If (m_App.sheets.Count = 0) Then Exit Sub ' no sheets
m_App.sheets(1).Name = Format$(Date, "mmm dd yyyy")
conn.Open "Provider=Microsoft.Jet.OL EDB.4.0;Pe rsist Security Info=False;Data Source=" & App.Path & "\db.mdb"
tblName = Format$(Date, "mmm dd yyyy")
sql = "CREATE TABLE [" & tblName & "] ("
For j = 1 To 10
sql = sql & "[" & m_App.sheets(1).cells(1, j).Value & "] TEXT(100), "
Next j
sql = Left(sql, Len(sql) - 2) & ")"
conn.Execute sql ' create the table
For i = 2 To 1441
sql = "INSERT INTO [" & tblName & "] ("
For j = 1 To 10
sql = sql & "[" & m_App.sheets(1).cells(1, j).Value & "], "
Next j
sql = Left(sql, Len(sql) - 2) & ") VALUES("
For j = 1 To 10
sql = sql & "'" & m_App.sheets(1).cells(i, j).Value & "', "
Next j
sql = Left(sql, Len(sql) - 2) & ")"
conn.Execute sql
Label1.Caption = "Inserted Item: " & i
DoEvents
Next i
DoEvents
conn.Close
Set conn = Nothing
m_App.sheets(1).Move After:=m_App.sheets(2) ' m_App.Sheets.Count)
m_App.ActiveWorkbook.Save
m_App.ActiveWindow.Close
m_App.Quit
Set m_App = Nothing
Exit Sub
SaveErr:
MsgBox Err.Number & ":" & Err.Description
On Error GoTo 0
End Sub
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Long
Dim j As Long
Dim strLine As String
Dim sql As String
Dim tblName As String
On Error GoTo SaveErr
Dim m_App As New Excel.Application
'Dim m_WB As Workbook 'Active Workbook for this excel instance
'Dim m_WS As Worksheet 'Active Worksheet
Dim WBfileName As String
WBfileName = App.Path & "\test.xls" ' + "\WB\Today.xls"
If m_App Is Nothing Then Exit Sub ' application did not get created
m_App.Workbooks.Open FileName:=WBfileName
If (m_App.sheets.Count = 0) Then Exit Sub ' no sheets
m_App.sheets(1).Name = Format$(Date, "mmm dd yyyy")
conn.Open "Provider=Microsoft.Jet.OL
tblName = Format$(Date, "mmm dd yyyy")
sql = "CREATE TABLE [" & tblName & "] ("
For j = 1 To 10
sql = sql & "[" & m_App.sheets(1).cells(1, j).Value & "] TEXT(100), "
Next j
sql = Left(sql, Len(sql) - 2) & ")"
conn.Execute sql ' create the table
For i = 2 To 1441
sql = "INSERT INTO [" & tblName & "] ("
For j = 1 To 10
sql = sql & "[" & m_App.sheets(1).cells(1, j).Value & "], "
Next j
sql = Left(sql, Len(sql) - 2) & ") VALUES("
For j = 1 To 10
sql = sql & "'" & m_App.sheets(1).cells(i, j).Value & "', "
Next j
sql = Left(sql, Len(sql) - 2) & ")"
conn.Execute sql
Label1.Caption = "Inserted Item: " & i
DoEvents
Next i
DoEvents
conn.Close
Set conn = Nothing
m_App.sheets(1).Move After:=m_App.sheets(2) ' m_App.Sheets.Count)
m_App.ActiveWorkbook.Save
m_App.ActiveWindow.Close
m_App.Quit
Set m_App = Nothing
Exit Sub
SaveErr:
MsgBox Err.Number & ":" & Err.Description
On Error GoTo 0
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had to compile without this option so it will go in a SP. Thanks for the direction- I'll let you know how it goes.
Private Sub Form_Load()
Dim m_App As New Excel.Application
Dim m_WB As Workbook 'Active Workbook for this excel instance
Dim m_WS As Worksheet 'Active Worksheet
Const WBfileName = App.Path + "\WB\Today.xls"
If m_App = Nothing Then Exit Sub ' application did not get created
If (m_App.Workbooks.Count = 0) Then Exit Sub ' no workbooks
If (m_App.Sheets.Count = 0) Then Exit Sub ' no sheets
m_App.Workbooks.Open FileName:=WBfileName
m_App.Sheets(1).Name = Format$(Date, "mmm dd yyyy")
m_App.Sheets(1).Move After:=m_App.Sheets(2) ' m_App.Sheets.Count)
m_App.ActiveWorkbook.Save
m_App.ActiveWindow.Close
m_App.Quit
End Sub