Access.application throwing exception

I use the following code to open an instance of Access to do some table maintenance when my Windows Form application starts.

The user is presented with an OpenFile dialog box and selects the database location, and this is written to settings and saved then,

[code]Dim ac As New Access.Application 'open access and load the standard database

Try

ac.OpenCurrentDatabase(My.Settings.dataLoc2)

Catch ex As Exception

MsgBox("Please report " & ex.Message & "to the Author", MsgBoxStyle.OkOnly)

ac.Quit()

ac = Nothing

Me.Close()

End Try[/code]

The application runs perfectly for most users, but two report an exception is raised "Attempted to read or write protected memory. This is often an indication that other memory is corrupted"

I have looked at other posts reporting that same error message - and they are no help to me at all, what am I missing




Answer this question

Access.application throwing exception

  • djchapin

    hi,

    mmm i'm not sure from this answer but that happend once to me when you use openfiledialog and you build code on that you are not sure if the user hit open , cancel ,or even the user closed the dialog without  open anything so the opendialog return nothing and your code depend on openfiledialog result so it will throw exception

    so i guess you have to do something like this

    dim result as dialogresult = dialogfile.showdialog()

    if result = dialogresult.ok and dialogresult.filenames <> nothing then

    'put your code here

    end if

    hope this helps



  • Mareen Philip MSFT

    Any suggestions Maybe a different approach I could try. Basically I need to either create or replace a query and two tables in the existing Access database, and do it as the app opens.

  • Mostafa Omar


    On which line of code does the error occur



  • Vytas

    Paul, thank you. That works perfectly.

    Shaka - good try, but I was already testing the setting of the property in earlier code.



  • StevenR2


    Does it make any difference whether you use CreateObject instead of New when instantiating Access

  • bodalal

    The text is returned in the message box within the catch, so this would indicate it is coming from the line of code within the try.

  • Access.application throwing exception