UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Excel Process Still Running After Access Quits Xl    
 
   
lateron
post Mar 11 2012, 11:03 PM
Post #1

UtterAccess Enthusiast
Posts: 62
From: NSW, Australia



Hi, Out of my depth using code to update an Access field from columns in XL 2003 spreadsheet. Works except Excel is still a running task in Windows (XP or 7 x64) after code finishes.
So if user tries to open same XL file manually after code run, there is brief flash on screen then XL runs invisible mode, as it does for the update to Access. But if end XL task in Task Manager, XL file opens correctly.
All code re XL & jist of Access operations is below ["......" replaces common Access code that's irrelevant I think]:

Sub GetXL_Data(Optional bInputBox As Boolean)

Dim xlApp As Excel.Application, xlWBk As Excel.Workbook
Dim xlSheet As Excel.Worksheet, xlRange As Excel.Range 'Dim xl objects
Dim db As DAO.Database
Dim rsHTbl As DAO.Recordset
Dim Unfound(9) As String 'Array 0-9
...........

'OPEN XL FILE
Set xlApp = New Excel.Application 'CreateObject("Excel.Application") is older way?
' open the workbook file
Set xlWBk = xlApp.Workbooks.Open(strPath & strFileName & ".xls")
' select the desired worksheet in the file
Set xlSheet = xlWBk.Worksheets(strSheetName)
xlSheet.Activate
..........
xlApp.Visible = False
..........

XL File names into variables
HWB = xlApp.ActiveWorkbook.Name
HSh = xlApp.ActiveSheet.Name
.........

'Set Access variables
Set rsHTbl = db.OpenRecordset(strHTbl, dbOpenDynaset)
U = -1 'Initialise variable for Unknown data
CopyCol = "A"
'DATA FROM XL SHEET into variable
For HR = 3 To 70 'Rows to search
'Get data from XL (@ row 70, code to repeat for another column)
........................

strFind = "[ID#]=" & vID
With rsHTbl
.MoveFirst
.FindFirst strFind
If .NoMatch Then ..........
.................
End If
.Edit
........................
End With
Next HR

'LIST UNFOUND DATA
If U < 0 Then
MsgBox "ALL DATA COPIED into Access"
GoTo END_UNKNOWN_DATA
End If
If U < 6 Then
Queries = MsgBox("ERRORS with THIS DATA:-" & vbCrLf & _
Unfound(0) & vbCrLf & _
Unfound(1) & vbCrLf & _
Unfound(2) & vbCrLf & _
Unfound(3) & vbCrLf & _
Unfound(4) & vbCrLf & _
Unfound(5) & vbCrLf & _
" in XL SHEET" & vbCrLf & _
"..Fix & ...RE-RUN [this code].", vbOKOnly, "ERROR")
End If
If U > 5 Then
...[similar to < 6 code]
End If

END_UNKNOWN_DATA:
Erase Unfound
U = Empty
Queries = ""

Next 'Another XL Sheet to do?
GoTo ResetVariables

Err_Handler:
.............

ResetVariables:
xlApp.Visible = True
xlWBk.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlWBk = Nothing
Set xlApp = Nothing
Set rsHTbl = Nothing
E: bInputBox = Empty 'If didn't Get Data, this is only var set

End Sub
Go to the top of the page
 
+
 
Start new topic
Replies
lateron
post Mar 19 2012, 01:12 AM
Post #2

UtterAccess Enthusiast
Posts: 62
From: NSW, Australia



QUOTE (BananaRepublic @ Mar 15 2012, 04:29 AM) *
This is really up to you to decide what is appropriate..................................................
I hope that the above help illustrates the considerations you have to think about what you're going to do with your Excel instance and what is the best approach.
Best of luck!


BananaRepublic, thanks for taking the time to explain in simplier terms. I'm thinking of hybrid of parts of above code & my original. Thanks everyone for your time & help.

Lateron
Go to the top of the page
 
+

Posts in this topic


Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 12:58 PM