MsAccessNL
Member
- Local time
- Today, 01:35
- Joined
- Aug 27, 2022
- Messages
- 219
I have this Runcode module that i use a lot with coding. You can run a private event in the vbe editor. It only toggle the Numlock on and off. I tried a lot (with the code from this forum). I narrowed the problem down. The CheckNumlock function works, stand alone, but in the code beneath it always gives CheckNumlock False even it it is true. Sleep the code didn't help.
	
	
	
		
CheckNumlock function:
	
	
	
		
 
		Code:
	
	
	Public Sub RunCode()
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' This Module is made by Daniel Sanders MsAccessNL 16-feb-2022
    ' First setfocus to Procedure then Type Runcode in the immediate window
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Const vbext_pk_Proc = 0
    Dim sProcedure As String, sFormName As String
    Dim lActiveLine As Long, sTemp As String
   
    Application.VBE.ActiveCodePane.GetSelection lActiveLine, 0, 0, 0 'get the activeLineNumber
    sFormName = Application.VBE.SelectedVBComponent.Name
    sProcedure = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(lActiveLine, vbext_pk_Proc)
   
    sTemp = "Call " & sFormName & "." & sProcedure
    SendKeys (sTemp), True ' False is default, True waits till kestroke is done
    SendKeys ("~"), True ' sometimes numlock will toggle
    'Sleep (500)
    Call CheckNumLock
End SubCheckNumlock function:
		Code:
	
	
	      Const VK_NUMLOCK = &H90
      Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Sub tblxx_Maschinen_ID_KeyPress(KeyAscii As Integer)
Public Function CheckNumLock() As Boolean
        Dim keys(0 To 255) As Byte
        GetKeyboardState keys(0)
        CheckNumLock = keys(VK_NUMLOCK)
        Debug.Print CheckNumLock
        'If CheckNumLock = False Then ToggleNumLock
End Function
			
				Last edited: 
			
		
	
								
								
									
	
		
			
		
		
	
	
	
		
			
		
		
	
								
							
							 
	 
 
		 
 
		 
 
		 
 
		 
 
		