Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I need to run access database from windows form, but I cant find how to set macro security on low level.

This is vbs:

Dim PokreniKF
Set PokreniKF = createobject ("access.application")
PokreniKF.runcommand 10
PokreniKF.automationsecurity = 1
PokreniKF.opencurrentdatabase "F:\KF.mdb"
PokreniKF.usercontrol = true
Set PokreniKF = Nothing

How I can convert this to c#?
Posted

You will need to reference Microsoft.Office.Interop.Access (I choose version 11), and Office 11.


I am not sure I have the argument right for AcCommand.acCmdZoom10 but this code will work for you.

C#
Type applicationType = Type.GetTypeFromProgID("Access.Application");

Microsoft.Office.Interop.Access.Application application = null;
try
{
    
    application = Activator.CreateInstance(applicationType) as Application;
    if (application != null)
    {
        application.RunCommand(AcCommand.acCmdZoom10);
        application.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow;
        application.OpenCurrentDatabase("F:\\KF.mdb", false, null);
        application.UserControl = true;
    }
}
finally
{
    if (application != null)
    {
        application.Quit(AcQuitOption.acQuitSaveAll);
    }
}
 
Share this answer
 
Thank you, this going to help me a lot.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900