Changing Profile at Document Activate Event causes Unhandled Access Violation

Discussion in 'AutoCAD' started by Jarod Arney, Aug 8, 2003.

  1. Jarod Arney

    Jarod Arney Guest

    I am writing a VBA program to change the active profile in AutoCAD based on
    a value assigned to individual drawings. The code seems to work if manually
    triggered through a macro in the current drawing, but when I try to adapt it
    to automatically trigger when the user switches between multiple open
    drawings I get a "FATAL ERROR: Unhandled Access Violation Reading ###
    Exception at ###". The numbers change each time. The event handler seems to
    be working because the code checking for the profile assigned to the drawing
    works but the following line causes the error.

    AutoCAD.preferences.Profiles.ActiveProfile = strProfile

    where strProfile is the retrieved value. The previous line is in an If..Then
    loop that checks the validity of the strProfile value so I think the problem
    has something to do with AutoCAD getting confused between the different open
    drawings. I can include more code, but there are now three forms with code,
    and four modules so it's a little hard to draw the line on what to include.

    Any help would be appreciated guys.

    Jarod Arney
    "Do or do not, there is not try."
     
    Jarod Arney, Aug 8, 2003
    #1
  2. Jarod Arney

    Jarod Arney Guest

    I found an answer. It was a timing issue. Triggering it based on window
    activation produced odd results. By moving the trigger to an EndOpen event
    everything seems to work fine. I did come up with another problem when
    closing an active document, but that's in a later post.
     
    Jarod Arney, Aug 11, 2003
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.