Opening Access report via .net working, but not working
I am trying to open an access report through .net. I can open it in normal mode using Access.AcView.acViewNormal, but it's not what I want to do because that prompts the user to save the first and then it can be viewed. I want the report to pop up and it seems .acViewPreview or .acViewReport is what i should use, but it's not popping up.
It does open up a process and seems to be opening, but i can't see the report. Perhaps it's closing really fast. The following is the code I have currently
private void buttonResults_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.Application();
oAccess.OpenCurrentDatabase("D:\\path.mdb",true);
try
{
oAccess.DoCmd.OpenReport("rptChartData", Microsoft.Office.Interop.Access.AcView.acViewPreview);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
What am i doing wrong?? Thanks in advance...
I don't know Dot Net. I put this code in an Excel module and it created an Access instance and displayed my report. The key seemed to be oAccess.Visible = True
Without setting Visible = True, Access opened (and remained open) with the report but was just not visible.
Dim strDbFullPath As String
Dim oAccess As Access.Application
strDbFullPath = "C:\Access\webforums\whiteboard2003.mdb"
Set oAccess = New Access.Application
oAccess.Visible = True
oAccess.OpenCurrentDatabase strDbFullPath, True
oAccess.DoCmd.OpenReport "rptFoo", acViewPreview
So I think this may not be a Dot Net issue, but standard behavior for an Access application instance.
精彩评论