Results 1 to 7 of 7
  1. #1
    numberguy is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    15

    Sendkeys replacement

    I have a data entry form where I need objects (controls in a form) to receive focus and lose focus without user input (several controls in a row). I have used the SendKeys {Tab} Macro command in the “On Got Focus” property area for the control. This worked fine until we upgraded to Windows 7 (and Vista). Now Access inadvertently turns off the Numeric Locks. I have read on the internet where this is a known issue and the SendKeys command should be avoided. I am trying to come up with a work around for using the SendKeys command and am not having much success. I have very limited VBA knowledge so I have been using macro commands to try to accomplish the task.
    The first work around I tried was using the GotoContol macro command. Using this command multiple times in a row results in the following error message (error no 2110)
    Microsoft Access can’t move the focus to the control (control name)
    The Control may be a type that can’t receive focus, such as a label
    The control’s Visible property may be set to no


    The control’s Enable property may be set to no.

    I have check the suggested control settings noted in the error and they are set properly. I get the error message when a have an embedded macro (in the On Got Focus event) in control 1 that uses the “GotoControl” command to move the focus to control 2 and a similar embedded macro in control 2 to move the focus to control 3 and so on. I do not believe the issue is with the control because I can use this command to move the focus to any of the controls, and as long as that receiving control does not have the macro moving focus to another control the macro works fine.

    Next I tried the “SetFocus” vba method. I used the following expression and used the RunCode macro command to invoke the expression via an embedded macro in the “On Got Focus” area for the control
    Function ToGrouping1()
    Dim MyVar1 As Single
    Forms!frmDTBEntry!GROUPING1.SetFocus
    End Function

    With this approach I get the following error message (error no 2766)
    The object doesn’t contain the Automation object
    You tried to run a visual basis procedure to set a property or method for an object. However, the component doesn’t make the property or method available for Automation operations.
    Check the component’s documentation for information on the properties and methods available for Automation operations

    Any help or ideas is greatly appreciated

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    Numberguy -

    Question? You stated: I have a data entry form where I need objects (controls in a form) to receive focus and lose focus without user input (several controls in a row).

    Why? Is there another process taking place when these controls receive the focus, a calculation or something else?

    Secondly, are these controls bound or unbound and what type of controls are they?

    As you know, there are several different ways of getting from point A to B on a form. However, knowing the answers to the above questions, may enable more precise help.

    All the best,

    Jim

  3. #3
    numberguy is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    15
    The controls are bound. They are all text boxes. What I am doing is giving the control focus and running a procedure that sets the value of another contol via a procdure embedded in the "On Lost Focus" property of the control (this was the only way I could figure out how to properly update a table with information derrived via a formula). So the control needs to get focus in order to lose focus to process the "On Lost Focus" procedure. These actions are performed several times in a row via several controls. There is never any operator data entry in any of these controls, they are all populated automatically.

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You can simply call the lost focus event from code instead of going through all of that:

    Code:
    Call Me.ControlNameHere.Lost_Focus
       DoEvents
    Call Me.Control2NameHere.Lost_Focus
       DoEvents
    Call Me.Control3NameHere.Lost_Focus
    ...etc.

  5. #5
    numberguy is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    15
    Thanks Bob
    I have embedded the following macro in the “On Lost Focus” event of a control where the user presses the enter Key to lose focus of the control.
    GoToCotrol
    Control Name REF
    I have embedded a macro in the “On Got Focus” of the control named REF the following macro
    RunCode
    Function Name UPDATELOSTFOCUS

    The VBA code for the UPDATELOSTFOCUS function is a follows:
    Function UpdateLostFocus()
    Call Me.FSCODE.Lost_Focus
    DoEvents
    Call Me.GROUPING1.Lost_Focus
    DoEvents
    Call Me.GROUPING2.Lost_Focus
    DoEvents
    Call Me.GROUPING3.Lost_Focus
    DoEvents
    End Function

    When I try to use the form I get the 2776 error again when Access tries to process the UPDATE LOST FOCUS function

    What have I done wrong?

    Thanks again!

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Okay, I think we still have a problem understanding each other.

    Why do you have a GoToControl happening there? Is there any way you can post a copy of your database so we can take a look and get a better picture of what you are really trying to do (forgetting for the moment anything about the lost focus events) - what calculations are you trying to do and what needs to be updated when and all of that. I fear that you have a long-roundabout way of doing something that could be done much simpler even without using the lost focus events.

  7. #7
    numberguy is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    15
    I am sure you are correct that there is probably a better way to accomplish my task, but this was the only way I could figure it out when I developed this database a few years ago. What I am doing is having Access retrieve information (for several controls in the form) from one table via a formula (in each of those controls) based off of data entered in other controls in the same form and update all of the information from all the controls in the form that do not contain a formula as a new record in a different table. The way I accomplished this was to use the SETVALUE command to set the result of the formula in the control to another control in the form via the ON LOST FOCUS event. The controls that had the values set via the above procedure are not visible and are bound to the table I want to be updated. All of the controls that contain the formulas for which the results are transferred to other controls have the tab stop property set as yes. This would allow the control to receive focus. In the On Got Focus property, I have embedded a macro (SendKeys {Tab}) which moved the focus to the next tab stop and allow the ON LOST FOCUS event to process. This all works fine except since the upgrade to Windows 7 the SendKeys command periodically turns the Num Lock off. That is the only issue I am trying to solve.
    As noted previously, I have tried to use the GoToControl command and the SetFocus method and have received errors.
    I tried your suggestion using the Call Me.NameOfControl.Lost_Focus – DoEvents and I get the 2766 error “The object doesn’t contain the Automation object”. I do not know why I am getting this error. I believe this approach could solve my issue if I can get around this error.
    As far as posting the data base, it is a large data base with numerous forms, queries, reports and macros (literally hundreds) and following my logic would be difficult at best. This one form is a very small piece of the data base.
    Thanks again for your help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Sendkeys replacement
    By numberguy in forum Forms
    Replies: 3
    Last Post: 10-29-2010, 07:20 AM
  2. Replacement in table with VB code
    By miziri in forum Access
    Replies: 2
    Last Post: 06-28-2010, 01:38 AM
  3. docmd.SendKeys "{F9}" in 2007
    By RickM in forum Access
    Replies: 4
    Last Post: 09-10-2009, 09:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums