Hi
Here is the C# version.
We can consider the Access.Control as the base class of the control on
report. e.g. the Textbox. Because VB.NET support latebinding implicitly,
we can call the property on the Access.Control directly. In C#, we have to
cast it to the correct type first, or we have to use reflection to do the
latebinding in C# as below.
As for the control that did not support controlsource, we have to use the
try...catch block to handle the issue.
private void button1_Click(object sender, System.EventArgs e)
{
Access.Application oAccess = new Access.ApplicationClass();
object oMissing = System.Reflection.Missing.Value;
oAccess.OpenCurrentDatabase(@"c:\Northwind.mdb",true,String.Empty);
oAccess.DoCmd.OpenReport("Customer Labels", Access.AcView.acViewDesign,
oMissing,oMissing,Access.AcWindowMode.acHidden,oMissing);
Access.Report rpt=null;
foreach(Access.Report o in oAccess.Reports)
{
if (o.Name == "Customer Labels")
{
rpt = o;
break;
}
}
foreach (Access.Control cnt in rpt.Controls)
{
try
{
System.Diagnostics.Debug.WriteLine(cnt.GetType().InvokeMember("ControlName",
System.Reflection.BindingFlags.GetProperty,null,cnt,null));
System.Diagnostics.Debug.WriteLine(cnt.GetType().InvokeMember("ControlSource
",System.Reflection.BindingFlags.GetProperty,null,cnt,null));
System.Diagnostics.Debug.WriteLine(cnt.GetType().InvokeMember("ControlSource
",System.Reflection.BindingFlags.SetProperty,null,cnt,new
object[]{"Test"}));
}
catch{}
}
}
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
STech - 29 Apr 2005 04:35 GMT
Perfect Peter! Thanks a lot!
> Hi
>
[quoted text clipped - 50 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 29 Apr 2005 06:58 GMT
Hi
Cheers!
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.