"Send Keys" Error

Posted on 2007-10-21
Last Modified: 2013-11-28
What is the best code to replace the "Send Keys" code error.
This seems to have something to do with the operating systems User Account Control (UAC). Turning off/disabling  UAC could be bad and I assume that disabling UAC is not a solution. Any other ideas anyone?

A user enters a wrong data type in a text field, and the "Before Update code verify the data and informs the user that wrong type of data was entered. Upon clicking the "ok" button of the msgbox dialog box, another error popup up.

Run-Time Error '70':
"Permission denied"

debug highlighted...
SendKeys Chr(27) & Chr(27)  

form this code....
' ******
Private Sub BldgDisttxt_BeforeUpdate(Cancel As Integer) '<====
Dim sError As String
Dim sMinValueCheck As String
Dim sMaxValueCheck As String
Dim bAllowFractions As Boolean
Dim bAllowX As Boolean

    sMinValueCheck = ">=0"
    sMaxValueCheck = "<=400"
    bAllowFractions = True
    bAllowX = False
    BldgDisttxtNewValue = VerifyValue(Nz(Me!BldgDisttxt.Value, ""), sError, sMinValueCheck, sMaxValueCheck, bAllowFractions, bAllowX)
    If BldgDisttxtNewValue = "" Then
        msgbox sError, vbInformation + vbOKOnly, "Invalid Value, press ESC twice to retry"
        SendKeys Chr(27) & Chr(27)                                  ' <==== Error Line
        Cancel = True
    End If
End Sub

I observed the "Send Keys" problem particularly when using Ms. Access 2003 in these operating systems:
Windows Vista, XP and Windows 2K - (if this would help).
Question by:billcute
    LVL 27

    Accepted Solution

    Chr(27)  is the Escape key. So the code appears to be trying to do what the message advises the user to do. Leave it out altogether and just use Cancel = True to cancel the update and return focus to the control

    If BldgDisttxtNewValue = "" Then
            msgbox sError, vbInformation + vbOKOnly, "Invalid Value, press ESC twice to retry"
            Cancel = True
    End If
    LVL 4

    Author Comment

    LVL 58

    Expert Comment

    SendKeys is an unsafe expression, blocked in sandbox mode.

    What you are really trying to do is undo the control (first Esc) and then undo the record (second Esc). This corresponds to:

        BldgDisttxt.Undo   ' provided it's a bound control
        Me.Undo    ' provided it's a bound form

    LVL 4

    Author Comment

    Thanks for additional the info. However...

         BldgDisttxt.Undo   ' It's not bounded
        Me.Undo    ' Form not bounded

    data is pasted unto main form via the following..
    Forms!frmMain!txtBldgDist = Me.BldgDisttxt


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now