Using Interop.Access to get controls in just Header section (or Body or Footer)

。_饼干妹妹 提交于 2021-02-11 10:02:44

问题


Could you advise how to use the Microsoft.Office.Interop.Access in C# to get all controls of just the header section of a specific Access form?

Thank you.


回答1:


All forms will have a Detail Section and forms will have additional Sections like FormHeader, FormFooter, PageHeaderSection, PageFooterSection, etc. if those elements exist in the form. Each of those Sections will have a Controls collection. Here is an example:

static void Main(string[] args)
{
    // this code requires the following COM reference in the project:
    // Microsoft Access 14.0 Object Library
    //
    var objAccess = new Microsoft.Office.Interop.Access.Application();
    objAccess.OpenCurrentDatabase(@"C:\Users\Public\Database1.accdb");

    string formName = "ClientForm";
    objAccess.DoCmd.OpenForm(formName, Microsoft.Office.Interop.Access.AcFormView.acDesign);
    Microsoft.Office.Interop.Access.Form frm = objAccess.Forms[formName];

    Console.WriteLine(String.Format("The FormHeader section of form [{0}] contains the following controls:", formName));
    foreach (Microsoft.Office.Interop.Access.Control ctl in frm.Section["FormHeader"].Controls)
    {
        Console.WriteLine();
        Console.WriteLine(String.Format("    [{0}]", ctl.Name));
        Console.WriteLine(String.Format("        {0}", ctl.GetType()));
    }
    objAccess.DoCmd.Close(Microsoft.Office.Interop.Access.AcObjectType.acForm, formName);
    objAccess.CloseCurrentDatabase();
    objAccess.Quit();

    Console.WriteLine();
    Console.WriteLine("Done.");
    Console.ReadKey();
}

Console output:

The FormHeader section of form [ClientForm] contains the following controls:

    [Auto_Logo0]
        Microsoft.Office.Interop.Access.ImageClass

    [Auto_Header0]
        Microsoft.Office.Interop.Access.LabelClass

Done.


来源:https://stackoverflow.com/questions/22020398/using-interop-access-to-get-controls-in-just-header-section-or-body-or-footer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!