Results 1 to 14 of 14
  1. #1
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212

    How to return to a form, do a go to control, and click on the control.

    Is there a way to add a macro action that would click on the control that has focus? Thanks.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What event would, then, trigger the Macro?

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    no; one can .SetFocus - but nothing more beyond that such as triggering the OnClick event of that control.... Microsoft is 'event driven' by its own fundamental self definition meaning that a human is there doing things... what you seek is typically designed via the use of Modules - whereby code is available to be called through out the application and is not limited to being inside a specific control.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Are you talking about clicking on a Command Button? If so, don't have a clue how to do it with a Macro; few serious developers use them, but using VBA code you don't even have to go to the Control to fire it, you just Call the OnClick Sub for the Control:

    Call cmdCommandButtonName_Click

    What, exactly, is your scenario? Are you opening a secondary Form, doing something, then closing it, and then wanting, on return to the primary Form, to fire the Command Button? If so, what is your code for doing this? What is the name of the Command Button?

    Linq ;0)>

  5. #5
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    I am in form 1, I open a second form, add a description and amount, close this form, return to the first form, go to control calledCopy411, which runs code to transfer the description and amount to a row on the first form rom the second form. I don't want the user to forget to click on Copy411 thus completing the transfer. So I would like to make it happen for them. Thanks for your help.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    As mentioned in post #4, you can use VBA from within the form's module to fire the On Click Event. If code is running within the form and you would like it to, seamlessly, fire the command buttons On Click event handler... Add this VBA to your existing code. The caveat is there needs to be VBA in the Copy_411 click event.

    Call Copy411_Click

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    If you open the secondary form in Dialog mode, the code in the primary form stops until the secondary form is closed...so something like this should do it:

    Code:
    DoCmd.OpenForm "SecondaryFormName", , , , , acDialog
    Call Copy411_Click

    Just replace SecondaryFormName with the actual name of the secondary form.

    Linq ;0)>

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Missinglinq View Post
    ...If you open the secondary form in Dialog mode,...
    If this suits the occasion, it is a superb thought for a rarely used option. The way I am understanding it is the user comes back to the primary form and does something to fire other code that, then, needs the click event. Could be wrong, though.

  9. #9
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    I used the On Got Focus, as my macro has already moved the focus to Copy411, wrote Copy411_click ( and it worked spectacularly). Thanks everyone for our help.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps I am alone. But, I am having trouble understand the User's workflow. I am glad to hear you have had some success. Are you sure the On Focus is the correct event to use? What happens if the user sets focus on the control multiple times or before it is desired the code be executed?

    Choosing the correct event is not the easiest thing to do and should be tested as if the User is trying to break things.

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I don't really understand it, either, and it would be interesting to know. Also interesting to know if Copy411 is, in fact, a Command Button or something else.

    Linq ;0)>

  12. #12
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    The first form has many such command buttons set up to transfer each row of data to the other side of the form. I have never had any problems with the way the user interfaces with the command buttons.

    Copy411 is a command button, it calls the following code on click, and copies data from two fields, into 2 other fields. If the user clicked on it, it would do the transfer (I am using a DLookup field on the first form to look up the data on the second form). When I get back to the first form with the focus on Copy411, I call Copy411_click, and copy 412_click. I don't know if on focus is the best place, it seems to work at that point. The user could click it many times, it would still produce the desired result. They can always click on the command button before there is data in the fields being transferred, I think it would just transfer blank fields.


    Function CopyFields(Source$, Destination$)


    'Copy fields fromform Source$ to form Destination$.
    'Only fields withmatching ControlSource names will be copied.

    On Error ResumeNext 'Disable error trapping

    For COUNTER = 1 ToForms(Source$).Count
    'Try to get acontrol source for control Counter.
    ControlField$ =Forms(Source$)(COUNTER).ControlSource

    'Did we get acontrol source? (Err=0)
    If Err = 0 Then
    'We have asource. Try to copy it to the destination
    Forms(Destination$)(ControlField$)= Forms(Source$)(ControlField$)
    End If
    Err = 0 'Clear any errors
    Next COUNTER
    End Function

    Thanks for your help. I hope I have explained it sufficiently.

  13. #13
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Abacus1234 View Post

    ...Copy411 is a command button...
    Then, as I said, there's no need to move Focus to it. It doesn't matter where the Focus is, on the Form, a simple

    Call Copy411_Click

    will cause its code to fire. But if what you're doing works for you, with no undesired effects, use it!

    Glad we could help!

    Linq ;0)>

  14. #14
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Thanks again.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-27-2014, 01:06 PM
  2. Replies: 2
    Last Post: 11-14-2014, 03:07 PM
  3. Replies: 10
    Last Post: 02-20-2013, 07:04 AM
  4. tab control - firing a page on-click event
    By Chuck55 in forum Programming
    Replies: 7
    Last Post: 05-01-2012, 09:57 AM
  5. Replies: 3
    Last Post: 03-29-2012, 12:40 PM

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