-
October 4th, 2011, 10:24 AM
#1
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!
-
October 4th, 2011, 12:56 PM
#2
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?
-
October 4th, 2011, 01:08 PM
#3
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.
-
October 4th, 2011, 01:37 PM
#4
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.
-
October 4th, 2011, 01:38 PM
#5
Re: Specify to open Access 2000
Originally Posted by jo15765
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.
-
October 4th, 2011, 01:52 PM
#6
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.
-
October 4th, 2011, 02:26 PM
#7
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.
-
October 4th, 2011, 02:28 PM
#8
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.
-
October 6th, 2011, 05:47 AM
#9
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.
-
October 7th, 2011, 12:34 PM
#10
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.
-
October 7th, 2011, 01:23 PM
#11
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.
-
October 7th, 2011, 01:28 PM
#12
Re: Specify to open Access 2000
DataMiser how would I check my reference?
-
October 7th, 2011, 09:36 PM
#13
Re: Specify to open Access 2000
Always use [code][/code] tags when posting code.
-
October 8th, 2011, 07:58 PM
#14
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.
-
October 10th, 2011, 03:49 PM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|