I currently have a table that stores the Excel file name(field:Spreadsheet) as well as the DateLastModified(fieldateModified). Now what I'd like to do is pull in the value from a single cell(cell:CntrlNm) in one of the worksheets(worksheetetails$) into that same table(table:Spreadsheets). Below is my code for the first step:
Private Sub Form_Open(Cancel As Integer)
'Set menu title
Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property, CapStr As String
Set dbs = CurrentDb ' Define Database object.
Set cnt = dbs.Containers!Databases ' Define Container object.
Set doc = cnt.Documents!SummaryInfo ' Define Document object.
CapStr = doc.Properties("Title")
'Prepare the database on opening the form
Dim Posst As DAO.Recordset
Dim savwks As String
Set Posst = CurrentDb.OpenRecordset("Spreadsheets", dbOpenTable)
'Delete contents of Spreadsheets Table
Do Until Posst.EOF
If Posst.Fields("Loaded") = -1 Then savwks = Posst.Fields("Spreadsheet")
Posst.Delete
Posst.MoveNext
Loop
'Read new Spreadsheets available
myname = Dir(CurrentDb.Name, vbNormal)
mypath = Left$(CurrentDb.Name, (Len(CurrentDb.Name) - Len(myname)))
'BeginTrans
myname = Dir(mypath + "*.XLS")
Do While myname <> "" ' Start the loop.
Posst.AddNew
Posst.Fields("Spreadsheet").Value = myname 'Set the filename
Posst.Fields("DateModified").Value = FileDateTime(mypath + myname) 'Set Date Modified
If myname = savwks Then Posst.Fields("Loaded") = -1
Posst.Update
myname = Dir ' Get next entry.
Loop
'CommitTrans
Posst.MoveLast
XLcnt = Posst.RecordCount
If XLcnt > 0 Then Me.Caption = CapStr & " with " & XLcnt & " spreadsheets"
If XLcnt = 0 Then
MsgBox "No Spreadsheets with data found."
Posst.Close
Quit
End If
'Close the recordset
Posst.Close
Call ImportFromExcel
End Sub
Please advise. I'm looking into all possible ways to extract the CntrlNm value associated to the Spreadsheet it is pulling from. Thank you in advance.
Private Sub Form_Open(Cancel As Integer)
'Set menu title
Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property, CapStr As String
Set dbs = CurrentDb ' Define Database object.
Set cnt = dbs.Containers!Databases ' Define Container object.
Set doc = cnt.Documents!SummaryInfo ' Define Document object.
CapStr = doc.Properties("Title")
'Prepare the database on opening the form
Dim Posst As DAO.Recordset
Dim savwks As String
Set Posst = CurrentDb.OpenRecordset("Spreadsheets", dbOpenTable)
'Delete contents of Spreadsheets Table
Do Until Posst.EOF
If Posst.Fields("Loaded") = -1 Then savwks = Posst.Fields("Spreadsheet")
Posst.Delete
Posst.MoveNext
Loop
'Read new Spreadsheets available
myname = Dir(CurrentDb.Name, vbNormal)
mypath = Left$(CurrentDb.Name, (Len(CurrentDb.Name) - Len(myname)))
'BeginTrans
myname = Dir(mypath + "*.XLS")
Do While myname <> "" ' Start the loop.
Posst.AddNew
Posst.Fields("Spreadsheet").Value = myname 'Set the filename
Posst.Fields("DateModified").Value = FileDateTime(mypath + myname) 'Set Date Modified
If myname = savwks Then Posst.Fields("Loaded") = -1
Posst.Update
myname = Dir ' Get next entry.
Loop
'CommitTrans
Posst.MoveLast
XLcnt = Posst.RecordCount
If XLcnt > 0 Then Me.Caption = CapStr & " with " & XLcnt & " spreadsheets"
If XLcnt = 0 Then
MsgBox "No Spreadsheets with data found."
Posst.Close
Quit
End If
'Close the recordset
Posst.Close
Call ImportFromExcel
End Sub
Please advise. I'm looking into all possible ways to extract the CntrlNm value associated to the Spreadsheet it is pulling from. Thank you in advance.