Reputation: 91
I need a link (most likely button, or similar) within my Visual Studio 2010 Windows form (c#), that will open up a pre-developed access form. Is this tricky or is it simpler than it sounds =P
Regards, Bserk
Upvotes: 0
Views: 6249
Reputation: 60556
Assuming you mean an Microsoft Access Database, you can use System.Diagnostics.Process
to open any file / programm.
Process.Start("PathAndFileNameOfYourAccessDb");
Upvotes: 1
Reputation: 7314
The simplest way of doing this is to use the /x command line switch. This launches a macro named on the command line.
Then just execute MSAccess with the name of the database and the /x switch like this:
"c:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "C:\Users\user\Documents\Database1.accdb" /x MyMacro
And access will open up the database with the named form.
Upvotes: 1
Reputation: 112782
You can use the Library NDde on CodePlex to communicate with the Access application through DDE.
This is a code snippt extracted from one of my projects:
using (DdeClient client = new DdeClient("MSAccess", Path.GetFileName(theAccessApp))) {
if (!TryConnect(client)) {
Process.Start(theAccessApp);
Thread.Sleep(2000);
if (!TryConnect(client)) {
Messagebox.Show("Could not start: " + theAccessApp);
return;
}
}
// Close the form if open
client.Execute("[Close 2, \"MyForm\"]", 10000);
// Open the form
string openCmd = String.Format("[OpenForm \"MyForm\",,,,,,\"{0}\"]", anyOpenArgsParam);
client.Execute(openCmd, 10000);
}
With
private static bool TryConnect(DdeClient client)
{
try {
client.Connect();
return true;
} catch (DdeException) {
try {
client.Connect();
return true;
} catch (DdeException) {
return false;
}
}
}
Upvotes: 1