Forum Discussion

Alexdaner's avatar
Alexdaner
New Contributor
3 years ago

Test form inside Microsoft Access accdb file Error

When I'm trying to open database using OpenCurrentDatabase method - I'm getting error.
I need to test forms. Not change DB. Check functionality of the form.

Code:

 

 

function Acess_Test() {
    MsAccess = Sys.OleObject("Access.Application");
    MsAccess.Visible = true;
    FileName = "C:\Public\Database2.accdb";
    MsAccess.OpenCurrentDatabase(FileName);
}

 

 

Error: 

On this PC code from Excel VBA - works well:

 

 

Sub MyFunc()
    Dim appAccess As New Access.Application
    appAccess.OpenCurrentDatabase ("C:\Public\Database2.accdb")
    appAccess.Visible = True
End Sub

 

 

 

  • Use double backslash when referring to file path,

     

    function Acess_Test() {
        MsAccess = Sys.OleObject("Access.Application");
        MsAccess.Visible = true;
        FileName = "C:\\Public\\Database2.accdb"; // <-- Use double backslash
        MsAccess.OpenCurrentDatabase(FileName);
    }

2 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Use double backslash when referring to file path,

     

    function Acess_Test() {
        MsAccess = Sys.OleObject("Access.Application");
        MsAccess.Visible = true;
        FileName = "C:\\Public\\Database2.accdb"; // <-- Use double backslash
        MsAccess.OpenCurrentDatabase(FileName);
    }