none
Microsoft.Office.Interop.Access Late Binding HELP!!! RRS feed

  • Question

  • Ok then, let me just tell you thanks for any help you might provide...

    I have a problem I need to use late binding on MsAccess in order to import some files to a database, but beeing a newbie i can't seem to make it "DoCmd" work on it can you guys give any help?

    There are several reasons why i must choose this option and not import it directly using OleDb for example.

    1 - The file I need to import has several text columns, where occasionally the size of the string is superior to 255 chrs, which makes it a Memo Type. Seeing that Oledb only reads 8 rows to guess the type it usually makes the fields Text type and then throws an exception. I also can't change the registry entry to change this behavior.

    2 - Can't use PIAS or VSTO because of the different versions it's going to be used;

    3 - The file layout may change so i can't do a proper Schema file to map the "memo columns";

    4 - Can't use external libraries and at most the target  framework is going to be 3,5 (can't update either) which makes it that more harder without dynamic type.

    So far i've been able to create an Access instance, create a new Temporary database, but can't seem to make the "DoCmd" property work to use "TransferSpreadsheet".

    object acc = Activator.CreateInstance(Type.GetTypeFromProgID("Access.Application"));
    
    Type accTipo = acc.GetType();
    object oMissing = Missing.Value;
    
    accTipo.InvokeMember("Visible",BindingFlags.SetProperty, null, acc,new object[] { true });
    accTipo.InvokeMember("NewCurrentDatabase",BindingFlags.Default|BindingFlags.InvokeMethod,null, acc, new Object[] { Environment.CurrentDirectory + @"/TEMP1.Accdb" });
    

    Again ty very much for your help.


    • Moved by CoolDadTx Wednesday, October 15, 2014 3:11 PM Office related
    Wednesday, October 15, 2014 11:51 AM

Answers

  • Hi,

    We don't need to use late binging to develop the Office solution. Office solution support ruing in defferent Office version. You can get more detail from link below:
    Running Solutions in Different Versions of Microsoft Office

    >> have tried that, but as it seems the target computer doesn't seem to recognize the proper pias.<<

    Which the version of Visual Studio are you using? By default, Office primary interop assemblies (PIAs) do not need to be installed on end user computers if the Embed Interop Types property of each Office PIA reference in the project is set to True, which is the default value. In this scenario, the type information for the PIA types that are used by your solution is embedded into the solution assembly when you build the project.

    I suggest that you check whether the Embed Interop Types property of each Office PIA reference in the project is set to True.

    You can get more detail about Office PIAs from link below:
    Office Primary Interop Assemblies

    Designing and Creating Office Solutions

    Office Solution Prerequisites for Deployment

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 16, 2014 8:34 AM
    Moderator

All replies

  • Hello,

    >  Can't use PIAS or VSTO because of the different versions it's going to be used;

    You are on the wrong avenue. You can use the lowest version of Access PIA you need to support. In that case you will be able to automate later versions also.

    Wednesday, October 15, 2014 3:37 PM
  • First of all ty for your time.

    I have tried that, but as it seems the target computer doesn't seem to recognize the proper pias. I seem to have failed to mention but the application most be "mobile" it doesn't have any instalation, hence one more dificulty. 

    this is what i call "Macgyver Developing" its on a client computer and i can't change an "hair" of the target computer, no updates, installs, registry editing, etc, etc. :(

    btw the target computer is windows xp, not quite sure of the service pack, and office 2007 also not sure of the service pack.

    Wednesday, October 15, 2014 3:59 PM
  • Hi,

    We don't need to use late binging to develop the Office solution. Office solution support ruing in defferent Office version. You can get more detail from link below:
    Running Solutions in Different Versions of Microsoft Office

    >> have tried that, but as it seems the target computer doesn't seem to recognize the proper pias.<<

    Which the version of Visual Studio are you using? By default, Office primary interop assemblies (PIAs) do not need to be installed on end user computers if the Embed Interop Types property of each Office PIA reference in the project is set to True, which is the default value. In this scenario, the type information for the PIA types that are used by your solution is embedded into the solution assembly when you build the project.

    I suggest that you check whether the Embed Interop Types property of each Office PIA reference in the project is set to True.

    You can get more detail about Office PIAs from link below:
    Office Primary Interop Assemblies

    Designing and Creating Office Solutions

    Office Solution Prerequisites for Deployment

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 16, 2014 8:34 AM
    Moderator