Hi,
I have been messing around with automating Access (I am attempting to actually manipulate the Access objects themselves so it requires going beyond data access) from a c# program (long story as to why, but any how...). I am dealing with databases that all have AutoExec macros within them which automatically run when the database opens, which I don't want the database to do. In Access this is bypassed by holding down the shift key. I have attempted to replicate doing this when opening from the C# program, in so doing I ported a piece of code over from VBA which did this very thing, using the SetKeyboardStat e API call. After monkeying around with the code a lot I finally arrived at this solution which does what I want, but I am not sure why: -
class OpenMdb
-
{
-
private const int VK_SHIFT = 0x10;
-
[DllImport("user32")]
-
public static extern long SetKeyboardState(ref byte lppbKeyStat);
-
[DllImport("user32")]
-
public static extern long SetFocus(long hwnd);
-
public static Access.Application NoAutoexec (int hWnd, string path, bool visible)
-
{
-
Access.Application app;
-
byte[] abytCodesSrc = new byte[256];
-
byte[] abytCodesDest = new byte[256];
-
app = new Access.Application();
-
app.Visible = visible;
-
abytCodesDest[VK_SHIFT] = 128;
-
SetKeyboardState(ref abytCodesDest[0]);
-
System.Windows.Forms.SendKeys.Send("+");
-
app.OpenCurrentDatabase(path, true, "");
-
SetFocus(hWnd);
-
return app;
-
}
-
}
-
The thing that has me puzzled is that the key to making this work was inserting the SendKeys statement. Sendkeys alone won't make this happen. The SetKeyboardStat e alone won't do what I am asking, but this seems to work. I think that I probably have a fundamental misunderstandin g of what the SetKeyboardStat e API is doing. I'd like to figure out why the conjunction of the API and Sendkeys is behaving this way. Any ideas?
0 1051 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: PM |
last post by:
Has anyone found a way to open a file exclusively where it
will fail if the file is already open, i have tried the
following
_FileStream = new FileStream(@"C:\Data.txt",
FileMode.Open, FileAccess.ReadWrite, FileShare.None);
which does not prevent me from opening the file even if
another user has the file open ie Notepad, it will prevent
me from saving the file in notepad until i close the file
in the app. I can then save changes made in...
|
by: MLH |
last post by:
Did A97, perchance, do away with the need for
an AutoExec macro to initiate an autoexec sequence
for databases? Or, must we still suffer with that hideous
macro?
|
by: Hank |
last post by:
I'm using Access 2000 and like many of you, I use the AutoExec
macro to open my main form. The problem is that for the first few
seconds, no form is visible and the user is looking at the list of
forms or tables in the database.
It would be nice if a form popped up immediately and just said
"Database Loading" or anything besides looking at the design screen. I
tried just opening a simple form with a label on it, which would, in
turn,...
|
by: Madhur |
last post by:
Hello
what about this nice way to open a file in single line rather than using
if and else.
#include<stdio.h>
void main()
{
FILE *nd;
clrscr();
fopen("c:\\autoexec.bat","r")&&printf("success") || printf("error opeing
|
by: darren via AccessMonster.com |
last post by:
Hi
I have multiple .mde FE's linked to an .mdb BE. The FE is distributed with an
Auto FE updater and as such all users are on the same version of the FE.
However, one user is getting "Action Failed" when the FE starts up and runs
AutoExec code.
I have seen some threads say this could indicate corruption but no ohter
users are experiencing this problem. In the past on a different db I had
something similar and it was down to the...
| |
by: Tim Streater |
last post by:
I have a form and a button to submit it. The button is made from:
<input type=button onclick='myHandler(this.form);'>
This all works fine except that in Safari 2.0.4, the enter/return keys,
if pressed, submit the form - bypassing my onclick handler.
I can partially fix this with:
<form onsubmit='return false;'>
|
by: lyle fairfield |
last post by:
"dpcman01" <bob@dpcman.com.auwrote in
news:48e4a87b$0$31804$afc38c87@news.optusnet.com.au:
Much of the code at the MVP site gave excellent results last century.
If I were opening a report in another db I would
(using Northwind 2007.accdb as an example)
1. Write a procedure in that db as:
|
by: Rex the Strange |
last post by:
Hello All,
I don't know if this is possible, but I'll give it a shot, here. I'm
sick of writing the following line of code in control event handlers:
if not visible then exit sub
Is it possible to override whichever routine processes the event
handler list so that no events are fired if the control is visible?
Something like this, for example:
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |