Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendKeys is messing with my NumLock key via VBA code in Access form

Tags:

I have the following code for an Access form. It appears as if the SendKeys is messing with my NumLock key by toggling it on and off as I open and close the form.

For perfectly valid reasons which I don't want to get into, I really do not want to completely hide the ribbon (I want the pull down menus still accessible) so the DoCmd.ShowToolbar command is not my preferred way of doing it.

Does anyone have any suggestions as to how I can modify the code below to accomplish what I want using the SendKeys command?

Using Access 2007 so the command

CommandBars.ExecuteMso "MinimizeRibbon" 

is not available to me.

By the way, database will be distributed so solution must be contained within database.

Private Sub Form_Close()  ' Unhide navigation pane     DoCmd.NavigateTo "acNavigationCategoryObjectType"     DoCmd.Maximize  ' Maximize the ribbon RibbonState = (CommandBars("Ribbon").Controls(1).Height < 75)  Select Case RibbonState     Case True         SendKeys "^{F1}", True     Case False         'Do nothing, already maximized End Select End Sub  Private Sub Form_Load() ' Hide navigation pane     DoCmd.NavigateTo "acNavigationCategoryObjectType"     DoCmd.Minimize Debug.Print Application.CommandBars.Item("Ribbon").Height ' Minimize ribbon RibbonState = (CommandBars("Ribbon").Controls(1).Height < 100)  Select Case RibbonState     Case True         'Do nothing, already minimized     Case False             SendKeys "^{F1}", False End Select End Sub 
like image 953
user12059 Avatar asked Sep 22 '14 15:09

user12059


People also ask

How do I use SendKeys in VBA?

Using the SendKeys Method You can use the SendKeys method in your Excel macros VBA code, to simulate keystrokes that you would manually input in the active window. The Keys argument is required, and is the key or keys that you want to send to the application, as text. The Wait option is optional.


2 Answers

It's a bug in Microsoft VBA. But there is a workaround.

Use F8 to run through the macro and find where it turns it off. It's usually after a SendKeys.

Then add an Sendkeys "{NUMLOCK}", True after the line to reverse the effect.

If you can't find it, just add it at the end and when it finishes, it will go back. Hopefully, if you add it during the show/hide process, it will work.

like image 114
icebird76 Avatar answered Oct 06 '22 20:10

icebird76


This is caused by :

Sendkeys "any key", False 

Instead of False as second parameter, use True.

like image 36
omari Avatar answered Oct 06 '22 20:10

omari