views:

138

answers:

2

Hi All

I've succesfully connected to a Microsoft Access database through the interop/COM.. I need to put some data into a combo box and Requery so I can get the information displayed.

         // Create app
         MsAccess.Application app = new MsAccess.Application();

         // Open the database
         app.OpenCurrentDatabase(
            @"C:/Prog.mdb"
            , false, "");

         // Open the form
         app.DoCmd.OpenForm("frmMain",
            MsAccess.AcFormView.acNormal,
            System.Reflection.Missing.Value,
            System.Reflection.Missing.Value,
            MsAccess.AcFormOpenDataMode.acFormPropertySettings,
            MsAccess.AcWindowMode.acWindowNormal, 
            System.Reflection.Missing.Value
         );

         app.Forms["frmMain"]["ctrlCustList"] .. . 
              // This gets me the control instance validly.. 
              // but do I put text in it?
         app.DoCmd.Requery("ctrlCustList");

Is there a way to send text into a control through the Interop? (I've seen GoToControl but that is for the focus) but I'm still lost and tried googling without much luck..

Thanks lb

A: 

In Access VBA, it is usual enough to set the RowSource of a combo to an SQL string (RowSourceType: Table/Query) or a value list (RowSourceType: Value List). The number of columns also need to be set. Is this what you mean?

Or do you mean you wish to set a particular value? This can be set by making the combo equal to the bound column of the required value.

Remou
Basically I have the information the combo box will already be populated with. The combo box's value affects the form: all I have to do is plug in one of the items and it should automatically do what it's meant to. I understand what you are saying, but how can I plug in the text, caption into this combo box thorough the .NET office/access interop? thanks.
lb
A: 

I don't know a damned thing about C#, but have you tried the obvious:

  app.Forms["frmMain"]["ctrlCustList"] = "value you want to set it to"

That's the way the code would work in Access itself.

David-W-Fenton
Read-only through C#/COM. Cannot be modified.
lb
Sorry! There has to be a way to do it, I just don't know what it would be.
David-W-Fenton
What you offered was genuine and intuitive, even if it's not the answer.
lb