How can I late bind to an MS Access Report from c#
This is how far I have gotten so far
I dont know how to do the open report call
Thanks
David - string message = "Failed to create Access application.";
-
Type accessType = Type.GetTypeFromProgID("Access.Application");
-
if (accessType == null)
-
{
-
throw new Exception(message);
-
}
-
accessApplication = Activator.CreateInstance(accessType);
-
-
string fileName = "C:\\Report.accdb";
-
-
accessApplication.GetType().InvokeMember(
-
"OpenCurrentDatabase",
-
System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod,
-
null,
-
accessApplication,
-
new Object[] { fileName });
5 3450
Try
DoCmd.OpenReport(
"Name", //ReportName
Access.AcView.acViewPreview, //View
System.Reflection.Missing.Value, //FilterName
System.Reflection.Missing.Value //WhereCondition
);
Regards,
AniJos
AniJos
Thanks
That code is for early binding when one uses
using Access = Microsoft.Office.Interop.Access;
I would like to use late binding to pick up the MS Access version of the machine the program is running on
Regards
David
hi david,
did you find a solution to this?
cheers
leddy
No I did not get a solution for this
This is how I've done it if anyone's interested.....
I have a function in the db called 'printReports' which is where the report is run, it takes three parameters, string dbfFileName, string dbfFilePath and string roundListName. -
object accessObject = null;
-
object[] Parameters;
-
-
string dbfFilePath = Path.GetDirectoryName(sf.Filename);
-
string roundListName = getTXT(dbfFilePath);
-
roundListName = roundListName.Split(',')[1];
-
roundListName = roundListName.ToUpper();
-
string dbfFileName = Path.GetFileNameWithoutExtension(sf.Filename) + ".dbf";
-
-
try
-
{
-
accessObject = Activator.CreateInstance(Type.GetTypeFromProgID("Access.Application"));
-
-
accessObject.GetType().InvokeMember(
-
"OpenCurrentDatabase",
-
BindingFlags.Default | BindingFlags.InvokeMethod,
-
null,
-
accessObject,
-
new Object[] { @"S:\DATA\SMART2\Data\SMART2_DB.mdb" });
-
-
accessObject.GetType().InvokeMember(
-
"Run",
-
System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod,
-
null,
-
accessObject,
-
new Object[] { "printReports", dbfFilePath, dbfFileName, roundListName });
-
-
accessObject.GetType().InvokeMember(
-
"CloseCurrentDatabase",
-
System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod,
-
null,
-
accessObject,
-
null);
-
-
}
-
catch (Exception ex)
-
{
-
string message = ex.Message;
-
while (ex.InnerException != null)
-
{
-
ex = ex.InnerException;
-
message += "\r\n----\r\n" + ex.Message;
-
}
-
MessageBox.Show(message);
-
}
-
finally
-
{
-
if (accessObject != null)
-
{
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(accessObject);
-
accessObject = null;
-
}
-
}
-
-
HTH
leddy
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike MacSween |
last post by:
Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
*********************************************************...
|
by: JD Kronicz |
last post by:
Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right...
|
by: Composer |
last post by:
I've read many postings about the problem of Access.References.IsBroken
and the consensus seems to be that late binding is the cure-all.
I have a very complex Access application that needs...
|
by: Zlatko Matić |
last post by:
I was reading about late binding, but I'm not completely sure what is to be
done in order to adjust code to late binding...
For example, I'm not sure if this is correct:
early binding:
Dim ws...
|
by: eBob.com |
last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been
wanting this capability for a long time. But it seems that I cannot
use it with Option Strict On. In an event handler I have ......
|
by: lgbjr |
last post by:
hi All,
I've decided to use Options Strict ON in one of my apps and now I'm trying
to fix a late binding issue. I have 5 integer arrays:
dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
|
by: Tim Roberts |
last post by:
I've been doing COM a long time, but I've just come across a behavior
with late binding that surprises me. VB and VBS are not my normal
milieux, so I'm hoping someone can point me to a document...
|
by: ADezii |
last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
|
by: Siv |
last post by:
hi,
I am converting an application that writes to an Excel spreadsheet and the
code trips the "option Strict" that I would like on because the parser says
"option Strict On disallows late...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |