Numlock and CAPSLOCK turned always ON in VBA Access - ms-access

Hello i have a form written in VBA Access , when i type or select some values from comboboz or text some values, my NUMLOCK And CAPSLOCK key are turning OFF, how to make that they ALWAYS will be ON , i can't figure how?

this has code that will check and set capslock, numlock and scrolllock.
It uses the windows APIs
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" _
(lppbKeyState As Byte) As Long
to check and set the keyboard state - with this API, other fun things are available, such as playing with the windows key.

Related

WinHelp to HTMLHelp for Visual Basic

I have inherited an old Visual Basic project. It still works except for the .hlp file on Windows 10.
I have found how I can convert the .hlp file to .chm.
Can anyone tell me how to replace the WinHelp with HTMLHelp in the VB project?
Thanks in advance
A correct answer depends on your exact requirements.
If you only want to start the old *.exe and display the *.hlp file (WinHelp) please navigate to the following link (search for Run WinHelp on Windows10) and read all further links inside:
How to convert HLP files into CHM files
Please note a tool called HHPMod especially for migrating context-sensitive F1 help. If F1 help has been used intensively in your old project, it can be difficult to switch from WinHelp (.hlp) to HTMLHelp (.chm).
But, you're already on the right track recommended ten years ago and still valid today "Help authors should move over to HTML Help 1.x (.chm)".
If you really want to recompile your old project then Download Visual Basic 6 example project may help you (see Download section).
First of all, you need to specify the help file that you want to use by setting e.g.:
App.HelpFile = App.Path & "\helpfile.chm"
You'll find all declarations in a module modHelp.bas like e.g.
Private Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, ByVal dwData As Long) As Long
Private Declare Function HTMLHelpTopic Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, ByVal dwData As String) As Long
Private Declare Function HtmlHelpSearch Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, dwData As HH_FTS_QUERY) As Long
Private Declare Function HtmlHelpIndex Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, dwData As HH_AKLINK) As Long
For further information see also Using a module for Visual Basic 6 projects
I have had success getting the Setup to install the WinHlp32 modules. I had to add some extra code into the Setup to get the modules to register.
I have only tried this on a couple of machines so far...
Thanks for your help.

Auto keyboard by using SendMessage

int VK_F_DOWN = GetVirtualKey('F', 0);
int VK_F_UP = GetVirtualKey('F', 1);
HWND hWnd = FindWindow(NULL,L"Calculator.exe");
SendMessage(hWnd, WM_KEYDOWN, toascii('F'), VK_F_DOWN);
SendMessage(hWnd, WM_KEYUP, toascii('F'), VK_F_UP);
It doesn't work on the Calculator.exe,however it can work on my visual studio when I change hWnd to HWND(0xFFFF).
And I also already got a non-zero hWnd. What am I missing here? Like authority or something?
Sounds like User Interface Privilege Isolation. As the Wikipedia article explains, you can request the access you want in your application manifest.
That said, you should be using SendInput rather than SendMessage. See one of Raymond Chen's blog entries on that point.

Declaring & Calling The Sleep API

I have read many threads on implementing the Sleep API however most are a step ahead of where I am at in terms of knowledge to some guidance would be greatly appreciated.
I have a macro in VBA which I would like to add pauses to, between steps (purely aesthetic rather than functional) however I am struggling with the basic declaring and calling.
I understand that first I must declare the api and that the code for this is...
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
however, I am confused with regards to where this should go. Should it go in a module of it's own or can it be stated at the top of the macro module?
Then to call the function do I simply add a line to the macro of...
Call Sleep (1000)
I'd appreciate it if anyone can help with this question and appreciate your patience with my basic grasp.
The declaration of Sleep should go to the top of a module. Standard coding module.
You can omit Call and just use
Sleep 1000 ' 1 second delay
anywhere within an existing sub, so
Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Main()
' wait 3 seconds
Sleep 3000
End Sub
an alternative without declaring the Sleep sub would be
Application.Wait Now + TimeValue("00:00:03") ' waits 3 seconds

How to get the idle time in Windows XP using VBA?

I would like to know the current idle time from user input on a given Windows XP machine programmatically. I am using VBA in MS Access. What options do I have?
I used the following to obtain the solution.
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastInputInfo Lib "user32" (plii As Any) As Long
Private Type LastInputInformation
cbSize As Long
dwTime As Long
End Type
Public Function GetUsersIdleTime() As Long
Dim lii As LastInputInformation
lii.cbSize = Len(lii)
Call GetLastInputInfo(lii)
GetUsersIdleTime = FormatNumber((GetTickCount() - lii.dwTime) / 1000, 2)
End Function
There are other parts of the system which can be idle such as,
CPU
Disk
Network
Other devices
To find out more regarding performance and other idle types see this SO post here.

How to Inspect Call Stack

Would it be possible to see the CallStack in VBA for MS Access 2003? That is to say, would it be possible to see from what procedure or function another function was called?
At runtime, View menu -> Call Stack (or press CTRL + L).
There is no programmatic way in VBA to view the call stack that I know of. The usual solution to this problem is to use some structure to track calling of functions, but it always seems like a kludge to me, and really of use only when programming (not at runtime), in which case it seems to me that the VBE's built-in capability for seeing the call stack is sufficient.
And, BTW, I always put the call stack button on my VBE toolbar, since it's one of the most frequently used functions for me. I also add the compile button -- I think it's crazy that it's not on the toolbar by default because it encourages people to code without ever forcing a compile. Then again, Access 2000 didn't even use Option Explicit by default (supposedly for consistency with the other apps using the VBE -- in other words, dumb down Access in order to make it consistent with apps that aren't nearly as code-heavy).
But I digress...
Eventually, add an optional parameter to your function, and pass the caller name that way. For forms, you can use Me.Name as the parameter.
Yes it's possible, BUT it's not quite usefull!
Private Declare Sub SetMode Lib "vba332.dll" Alias "EbSetMode" (ByVal lngMode As Long)
Private Declare Function GetCallStackCount Lib "vba332.dll" Alias "EbGetCallstackCount" (lngCount As Long) As Long
Private Declare Function GetCallStackFunction Lib "vba332.dll" Alias "EbGetCallstackFunction" (ByVal Lvl As Long, ByRef strBase As String, ByRef strModule As String, ByRef strFunction As String, ByRef Done As Long) As Long
Before use GetCallStackCount and GetCallStackFunction call SetMode(2), and after SetMode(1).