Opening MS Access database with Powershell?

0

I am trying to open a form in an access database using powershell:

$application = New-Object -ComObject Access.Application
$Fullpath = "path.accdb"
$application.OpenCurrentDataBase($Fullpath)
$application.docmd.OpenForm("frm")

I am getting the following error message:

Exception calling "OpenCurrentDatabase" with "1" argument(s): "Unable to cast COM object of type 'Microsoft.Office.Interop.Access.ApplicationClass' to interface type 'Microsoft.Office.Interop.Access._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

Has anyone seen this before/resolved this issue?

forms
powershell
ms-access
asked on Stack Overflow Sep 11, 2018 by Newbie • edited Sep 11, 2018 by Tomalak

1 Answer

0

I want you to try this.. I made this code and its working fine

$Db = "sampledb.mdb"
$cursor = 3 
$lock = 3

$conn = New-Object -ComObject ADODB.Connection 
$recordset = New-Object -ComObject ADODB.Recordset
$conn.Open("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=$Db")

$query = "Select * from LoginInfo"
$recordset.open($query,$conn,$cursor,$lock)

$recordset.Addnew() 
$recordset.Fields.Item("EmpID") = "1" 
$recordset.Fields.Item("UserName") = $username_txt.Text
$recordset.Fields.Item("PWord") = $password_txt.Text
$recordset.Fields.Item("EmpRole") = $userrole_combo.SelectedItem

$recordset.Update()
$recordset.close() 
$conn.close()
answered on Stack Overflow Sep 11, 2018 by Nher

User contributions licensed under CC BY-SA 3.0