Visual Basic Customization

Visual Basic Customization

Active Member
Posts: 10
Registered: ‎11-13-2006
Message 1 of 4 (96 Views)

Help - VBA Issues

96 Views, 3 Replies
05-20-2008 12:57 PM
Trying to run a VBA routine that has worked fine in AutoCAD 2008 but now gives me the following error when running in AutoCAD 2009.

FATAL ERROR: Unhandled Access Violation Writing 0x80534a4d Exception at 650bd6d3h

What the program does:
We have a prototype set of drawings that are stored in a network location. The routine will create a new set of drawings using database entries in Microsoft Access 2003. It works fine up until the same drawing each time. I've checked the drawing and find no issues w/ it. Interestingly, if I create a new dwg w/ the same name, it will process. Could there be content within a drawing that prevents it from being "Saved As" during a vba routine?
Code is listed below.

Private Sub GetFileNames()

Dim strFileName As String
Dim strFilePath As String
Dim strTempName As String
Dim strNewFName As String
Dim strNewPath As String
Dim strPath As String
Dim WS As Workspace
Dim DB As Database
Dim RS As Recordset

DBName = "Templates"
WSName = "M:\DesignForum\database\" + txtWSName.Text

Set WS = DBEngine.Workspaces(0)
Set DB = WS.OpenDatabase(WSName)
Set RS = DB.OpenRecordset(DBName, dbOpenTable)

strFilePath = ThisDrawing.Path

Do While Not RS.EOF
strPath = RS!TemplatePathName
strTempName = RS!TemplateFileName
strFileName = strPath + strTempName
strNewFName = strFilePath + "\" + txtJobNo + "_" + strTempName
ThisDrawing.Application.Documents.Open (strFileName)
ThisDrawing.SaveAs (strNewFName)
ThisDrawing.SaveAs (strNewFName)
End Sub
Distinguished Contributor
Posts: 150
Registered: ‎01-04-2007
Message 2 of 4 (96 Views)

Re: Help - VBA Issues

05-21-2008 05:10 AM in reply to: mboyer
Just as a check, have you stepped through each line of code with F8 and which line of code crashes it?
Active Member
Posts: 10
Registered: ‎11-13-2006
Message 3 of 4 (96 Views)

Re: Help - VBA Issues

05-22-2008 07:50 AM in reply to: mboyer
It seems to be at the line which does a Save As.
Valued Contributor
Posts: 73
Registered: ‎11-01-2006
Message 4 of 4 (96 Views)

Re: Help - VBA Issues

05-22-2008 02:18 PM in reply to: mboyer
>Try all of these typical things and see if it helps.
-pu r * n
-pu all n (until everything is purged)
(repeat process until everything is purged and no audit errors)

>If that doesn't help, in each environment (mspace, pspace, etc.):
Erase All
Save, Close, Reopen
-pu r * n
-pu all (untill everything is purged)

You can also try saving to a different dwg version then back, if you can, which may rewrite parts of the file that may be corrupted.

If all else fails... rebuild the file from a new one.

Good luck!
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.