-
August 19th, 2011, 03:42 AM
#1
Connecting to an Access Database Question
Firstly can I apologise if I have posted this in the wrong area as I am very new to this.
I am trying to write an application, that opens up a specific Access database, change the VBA module slightly, then close the database, saving the changes.
Now my code works but it doesn't seem to close Access down very well, causing the following errors:
Faulting application MSACCESS.EXE, version 12.0.6535.5005, time stamp 0x4bf5c550, faulting module ole32.dll, version 6.0.6002.18277, time stamp 0x4c28d53e, exception code 0xc0000005, fault offset 0x00047333, process id 0x13e0, application start time 0x01cc5dc3fb9eeb42.
Code:
Dim vAccess As Access.Application
Dim vVBProj As VBIDE.VBProject
Dim vVBComp As VBIDE.VBComponent
Dim vCodeMod As VBIDE.CodeModule
Dim vFound AsBoolean
Dim vSL AsLong
Dim vEL AsLong
Dim vSC AsLong
Dim vEC AsLong
Dim vtmpStr AsString
Dim vtmpStrBefore AsString
Dim vtmpStrAfter AsString
Dim vmyPos AsInteger
vAccess = New Access.Application()
vAccess.OpenCurrentDatabase(f)
vVBProj = vAccess.VBE.ActiveVBProject
ForEach vVBComp In vVBProj.VBComponents
vCodeMod = vVBComp.CodeModule
With vCodeMod
vSL = 1
vEL = .CountOfLines
vSC = 1
vEC = 255
vFound = .Find(Target:=vFind, StartLine:=vSL, StartColumn:=vSC, EndLine:=vEL, EndColumn:=vEC, WholeWord:=False, MatchCase:=False, PatternSearch:=False)
DoUntil vFound = False
x = x + 1
vtmpStr = vCodeMod.Lines(CStr(vSL), 1)
vmyPos = InStr(LCase(vtmpStr), LCase(vFind))
vtmpStrBefore = Mid(vtmpStr, 1, vmyPos - 1)
vtmpStrAfter = Microsoft.VisualBasic.Right(vtmpStr, Len(vtmpStr) - (vmyPos + 12))
vtmpStr = vtmpStrBefore + vReplace + vtmpStrAfter
vCodeMod.ReplaceLine(CStr(vSL), vtmpStr)
vSL = 1
vEL = .CountOfLines
vSC = 1
vEC = 255
vFound = .Find(Target:=vFind, StartLine:=vSL, StartColumn:=vSC, EndLine:=vEL, EndColumn:=vEC, WholeWord:=False, MatchCase:=False, PatternSearch:=False)
Loop
EndWith
Next vVBComp
vAccess.Visible = False
vAccess.Quit()
GC.Collect()
-
August 19th, 2011, 07:54 AM
#2
Re: Connecting to an Access Database Question
I have finally found the answer:
Change
vAccess.Quit()
to
vAccess.CloseCurrentDatabase()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|