Full Version: SendKeys "{DOWN}"
UtterAccess Forums > Microsoft® Access > Access Forms
Ibrahim
Hi All,
recently shifted my Access Application to Windows Vista.
Unfortunately the above VB command is not working and showing as "permission denied" (run time error 70).
Can you pls suggest any solution for the above issue.
Best regards,
Ibrahim
Doug Steele
SendKeys doesn't work with Vista.
The easiest approach would be not to use SendKeys (I've never used it in any application I've built).
Failing that, you could try the following code:
CODE
Option Explicit
  
Private Const KEYEVENTF_KEYUP = &H2
Private Const INPUT_KEYBOARD = 1
  
Private Type KEYBDINPUT
  wVk As Integer
  wScan As Integer
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
  
Private Type GENERALINPUT
  dwType As Long
  xi(0 To 23) As Byte
End Type
  
Private Declare Function SendInput Lib "user32.dll" ( _
  ByVal nInputs As Long, _
  pInputs As GENERALINPUT, _
  ByVal cbSize As Long _
) As Long
  
Private Declare Sub CopyMemory Lib "kernel32" _
  Alias "RtlMoveMemory" ( _
  pDst As Any, _
  pSrc As Any, _
  ByVal ByteLen As Long _
)
  
Public Function SendKeysA(ByVal vKey As Integer, Optional booDown As Boolean = False)
Dim GInput(0) As GENERALINPUT
Dim KInput As KEYBDINPUT
  
  KInput.wVk = vKey
  If Not booDown Then
     KInput.dwFlags = KEYEVENTF_KEYUP
  End If
  GInput(0).dwType = INPUT_KEYBOARD
  CopyMemory GInput(0).xi(0), KInput, Len(KInput)
  Call SendInput(1, GInput(0), Len(GInput(0)))
End Function

(that code comes from a discussion on the topic in Michael Kaplan's blog)
doctor9
Ibrahim,
agree with Doug -- SendKeys should be the last resort when all else has failed. Can you explain what you're trying to accomplish with the SendKeys statement? There maybe a better method of accomplishing the same thing.
Dennis
Ibrahim
hi all
Thanks for your quick response.
Oused this command to move the selection pointer to the next record in a list box.
I shall try to find the alternative to accomplish this simple task.
Thank you all again.
Best regards,
Ibrahim
doctor9
Ibrahim,

If this listbox is a single-select list, you'd probably be able to use code like this:
CODE
  
Private Sub cmdSelectNext_Click()
    Dim i As Integer
[color="green"]'   Make sure something is selected[/color]
    If Me.lstSelectedVendor.ItemsSelected.Count > 0 Then
[color="green"]'       Search through the all of the list items[/color]
        For i = 0 To Me.lstSelectedVendor.ListCount
[color="green"]'           Find the first list item that's selected[/color]
            If Me.lstSelectedVendor.Selected(i) = True _
               And i < Me.lstSelectedVendor.ListCount Then
[color="green"]'              If it's not already the last list item, select the next one[/color]
               Me.lstSelectedVendor.Selected(i + 1) = True
[color="green"]'              ...and that's it![/color]
               Exit Sub
            End If
        Next i
    End If
End Sub

Hope this helps,

Dennis
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.