send a keystroke to Access97 db with VBA

oravec

Board Regular
Joined
Apr 15, 2003
Messages
65
Hello,

Have been trying to enter data automatically to an Access97 mde file using Excel VBA. And have hit my next wall. When file opens, FrmLogin activates. the OK button must be clicked for db to proceed to next step(some macros run). The code below is what I am using so far. I have changed the focus on form to the OK button, but cant figure out how to send a command to activate OK button. Manually I either "left click on it" or depress "Enter" key. I want to automate this operation with VBA. I have tried a sendkey statement, but probally am not using the right syntax.
The following code: DoCmd.Close acForm, "FrmLogin", acSaveYes
closes form just fine, but doesn't run the macro that activates when OK button is used. Any help appreciated.

Thanks,
Cliff


Dim db As Access.Application
Sub test_opendb()
Set db = New Access.Application
db.OpenCurrentDatabase "c:\Program Files\opsnet\Opsnet20.mde"
db.Application.Visible = True
Forms!FrmLogin!OK.SetFocus
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Rather than trying to use sendkey to push the button you may be able to call the code behind the button directly. The sub behind the button will need to be declared as a Public Sub rather than Private one so you will need to check the code.
Then you can call it with something like:-

Sub test_opendb()
Dim db As Access.Application
Set db = New Access.Application
db.OpenCurrentDatabase "c:\Program Files\opsnet\Opsnet20.mde"
db.Application.Visible = True
db.Forms!FrmLogin.OK_Click
End Sub

HTH

Peter
 
Upvote 0
When I try running the code, it gives run-time error '2465' : application-defined or object-defined error, when it gets to the line: db.Forms!FrmLogin.OK_Click. Since this is a mde file I am trying to update, I am not sure I can look at the code.

cliff
 
Upvote 0
No, you won't be able to see the code behind a form in a MDE.
Do you have access to the original MDB file?

If you can find out what the code behind the button is you may be able to do the same thing from Excel.
If the macros that run are Access Macros as oppsed to VBA procedures you should be able to run them.

Peter
 
Upvote 0
I believe the code behind the button is VBA since I can't find it in the Macro section of mde file. I think that I have to activate OK button to have file work properly. When OK activates it sets db to allow data entry in other forms for today's date. If FrmLogin is closed without clicking OK, then other forms open up with last date when OK was clicked. Any ideas?

Cliff
 
Upvote 0
only other thing that I can think of to check is wether there is an accelator key on the buttton you can trigger?

I will have a look to see if I can see a way of sending Enter though.

Peter
 
Upvote 0
Cliff

I have had another little play. Try:-

Sub test_opendb3()
Dim db As Access.Application
Set db = New Access.Application
db.OpenCurrentDatabase "c:\Program Files\opsnet\Opsnet20.mde"
db.Application.Visible = True
Forms!FrmLogin.SetFocus
Forms!FrmLogin.OK.SetFocus
SendKeys ("~"), True
End Sub


Peter
 
Upvote 0
Peter,

Still no luck, all lines of code are accepted, when
line: Forms!FrmLogin.OK.SetFocus runs, I see OK button highlight.
When line: SendKeys ("~"), True runs, code is accepted, but nothing happens. I do apppreciate your help. Still frustrated in Arkansas.

Cliff
 
Upvote 0
I am out of ideas now, I tested that code on a db on my machine and it worked! :(
Perhaps someone else will have a suggestion!
 
Upvote 0

Forum statistics

Threads
1,221,553
Messages
6,160,468
Members
451,649
Latest member
fahad_ibnfurjan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top