My Assistant
|
|
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 |
|
|
|
![]() |
Mar 19 2012, 01:12 AM
Post
#2
|
|
|
UtterAccess Enthusiast Posts: 62 From: NSW, Australia |
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 |
|
|
|
lateron Excel Process Still Running After Access Quits Xl Mar 11 2012, 11:03 PM
cheekybuddha Hi,
The reason for this week be an unqualified re... Mar 12 2012, 02:43 AM
arnelgp CODESet xlApp = New Excel.Application 'CreateO... Mar 12 2012, 03:03 AM
cheekybuddha QUOTE Not, old in fact most efficient way.
'Mo... Mar 12 2012, 06:01 AM
arnelgp CODEUsing Set xlApp = CreateObject("Excel.... Mar 12 2012, 07:08 AM
BananaRepublic As a rule, I never create an office Application va... Mar 12 2012, 07:21 AM
arnelgp What a fine code you have there Mr.BananaRepublic,... Mar 12 2012, 08:29 AM
BananaRepublic If I didn't want anyone to take the code, then... Mar 12 2012, 09:50 AM
BananaRepublic Just to make it explicit for benefits of those unf... Mar 12 2012, 09:52 AM
arnelgp this one I learned! Mar 12 2012, 10:09 AM
lateron Thanks everyone.
cheekybuddha u put me on right tr... Mar 13 2012, 12:57 PM
cheekybuddha Hi lateron,
I'm glad you were able to find th... Mar 14 2012, 07:30 AM
lateron Thanks again cheekybuddha,
QUOTE Code tags are pur... Mar 14 2012, 08:15 PM
BananaRepublic QUOTE (lateron @ Mar 14 2012, 08:15 PM) E... Mar 14 2012, 10:29 PM![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 18th May 2013 - 12:58 PM |