CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    May 2011
    Posts
    44

    Specify to open Access 2000

    I am working on a computer that has Access2000 and Access20007 installed on it. I am using a form, and the background code was written in C#.....when I press one of the buttons on the form, it opens an access database. The problem is, since both 2000 and 2007 are installed it wants to open 2007. Is there a way to specify in the C# code to open Acess2000? The only way it is being called in the actual C# code is by using "Access.[what Access object it is going to run]"

    Let me know if I need to provide more info, or if this is possible, thanks!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Specify to open Access 2000

    Are you connecting to an access database (no UI) or are you opening an instance of the Access application?

  3. #3
    Join Date
    May 2011
    Posts
    44

    Re: Specify to open Access 2000

    I am not sure how to answer this question. I am opening an access database, and pulling in data from a query in that database. So I guess I am opening an instance of Access as well as connecting to a database?
    Last edited by jo15765; October 4th, 2011 at 01:17 PM.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Specify to open Access 2000

    There is no need to open an instance of Access to grab data, simply set your connection to use the database you want and use datareader, datatable or whatever class is needed for your task at hand.

    If you are using an Access object then you must specify the version when you reference or create the object in your code.
    Always use [code][/code] tags when posting code.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Specify to open Access 2000

    Quote Originally Posted by jo15765 View Post
    I am not sure how to answer this question. I am opening an access database, and pulling in data from a query in that database. So I guess I am opening an instance of Access as well as connecting to a database?
    Post your code that opens (or connects to) the Access database.

  6. #6
    Join Date
    May 2011
    Posts
    44

    Re: Specify to open Access 2000

    This is the onclick event of a button that I have on my form that opens the access database:
    Code:
                app = new Access.ApplicationClass();
                app.Visible = true;
                app.OpenCurrentDatabase(gcFile, false);
                textBox1.Text = app.CurrentDb().QueryDefs.SQL;

    And when I click this is when it starts to run the installation for Access2007
    Last edited by jo15765; October 4th, 2011 at 02:14 PM.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Specify to open Access 2000

    You are opening the Access application with COM. This causes the access.exe to open.

    What you want to do is to connect to the database through a database connection.

    Code:
    string conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\abc.mdb;Jet OLEDB";
    
    using( var cn = new OleDbConnection( conn ) )
    {
      using( var cmd = new OleDbCommand( "Select * from tablename", cn )
      {
          using( var reader = cmd.ExecuteReader( ) )
          {
            // access the data in each column
            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            }
          }
      }
    }
    You'll have to figure out the correct data connection string.

  8. #8
    Join Date
    May 2011
    Posts
    44

    Re: Specify to open Access 2000

    But I actually want it to open access. I just need it to open Access 2000 as opposed to 2007. Is there a command in C# where you can specify to open Access.Access2000 or something like that?
    Last edited by jo15765; October 4th, 2011 at 03:29 PM.

  9. #9
    Join Date
    Oct 2011
    Posts
    1

    Re: Specify to open Access 2000

    Hey,

    I take it this is a windows box your using?

    Sounds like Access 2007 is setup in the system path and so when you launch access it is launching 2007.

    If you go Start->Run and typ access does it launch access 2007? If so then you just need to modify the path setting to point to where the access 2000 exe is and not the access 2007 exe.

    Hope this helps.

  10. #10
    Join Date
    May 2011
    Posts
    44

    Re: Specify to open Access 2000

    Tellon --- If I go to start---> Run and type access I get an error that Windows can not find 'access' make sure you type the name correctly and then try again.

  11. #11
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Specify to open Access 2000

    Sounds like your reference is to the new version of access so when you call Access you are calling the new version. Check your references and see if you have other options, On my machine I have versions 10, 11, 12 available as com objects.
    Always use [code][/code] tags when posting code.

  12. #12
    Join Date
    May 2011
    Posts
    44

    Re: Specify to open Access 2000

    DataMiser how would I check my reference?

  13. #13
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Specify to open Access 2000

    Under project references
    Always use [code][/code] tags when posting code.

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Specify to open Access 2000

    The problem with adding the Microsoft.Office.Interopt.Access reference is the different versions. (Eg v11 and v12) are named the same so you can only add one to your project.

    What you might try is to use the COM tab and add a reference to an earlier Access version.

  15. #15
    Join Date
    May 2011
    Posts
    44

    Re: Specify to open Access 2000

    When I look at my solution explorer in Visual Studio, and I see Access, and when I double click on that it brings up a new window of the object browser. From there, it displays an endless number of options...I am lost as to where to check to see which version Visual Studio is set to call.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured