Results 1 to 7 of 7
  1. #1
    AbbHeDa is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    4

    Bring back focus to a form

    Hello!
    Sorry for my poor english, I'm using goole translate to write this post.

    I have problems to get focus back on a form.
    I have one form "MyForm" and one control "MyControl"


    On_exit on "MyControl" I run:


    Code:
     "Sub Makeback_up ()
     Dim SokUsb As String
    
     SokUsb = "g: \"
    
     DoCmd.OutputTo acOutputQuery, "qryBackUp" acFormatXLSX, SokUsb & "back_up" & Date & ". Xlsx"
     End Sub
    .
    The docmd.outputTo makes the form to deaktivete.
    (the event MyForm.deactivate is raise).
    I can not programaticly get the focus back to the form by Using "MyForm.setFocus" or any other way I tried.
    All help is appreciated.
    Thank you!!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    "MyForm" is the actual name of your form?

    So code following the OutputTo does not execute?

    You tried:
    Forms!MyForm.SetFocus
    Forms!MyForm!MyControl.SetFocus
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    AbbHeDa is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    4
    Thanks for your reply. I am very gratefulfor the help.

    I started over from scratch with a new databaseto streamline the problem.
    The last thing I want is to wasteyour time
    The error is easy to recreate.
    Database: databaseX.accdb
    table: tblA
    field: 1a text
    2a text
    3a text
    Query: qryA
    qrydef: SELECT tblA.* FROM tblA;

    Form: MyForm
    data source: tblA
    Controls: MyControl1a controlsource:1a
    MyControl2a controlsource:2a
    MyControl3a controlsource:3a
    event procedure:
    Private Sub MyControl1a_Exit(Cancel As Integer)
    Me.MyControl2a.SetFocus
    End Sub
    Private Sub MyControl2a_Exit(Cancel As Integer)
    Call MakeBack_up
    Form_MyForm.SetFocus
    Me.MyControl3a.SetFocus
    End Sub
    Sub MakeBack_up()
    DoCmd.OutputTo acOutputQuery, "qryA", acFormatXLSX, "c:\data\back_up.Xlsx"
    End Sub
    Enter a value in MyControl1a press tab enter a value in MyControl2a press tab and the focus is lost. The file is created.
    Add this to MyControl2a_Exit and you can see that the code is executed
    Me.MyControl3a.BorderColor = RGB(255, 0, 0)
    But there is still no focus on the form and I cant put a number in MyControl3a until I click in the form.
    Hope this better explains my problem.
    Henrik

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    I cannot replicate your issue. Do you want to provide project for analysis? Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    AbbHeDa is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    4
    Quote Originally Posted by June7 View Post
    I cannot replicate your issue. Do you want to provide project for analysis? Follow instructions at bottom of my post.
    Yes please!
    I really appreciate that you are taking your time with this.
    Henrik
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Okay, this is annoying. It is like the application no longer has focus. This can be demonstrated by double clicking on the Access app window border after running the OutputTo and then you can see that the control does have focus. It seems the OutputTo puts focus somewhere else in Windows or the desktop.

    Reason I didn't see the issue in the quick test I did was I used a form that had no textboxes and I ran code from button so the behavior you experienced wasn't evident. It was still good to see your effort as I can offer other comments. Don't need to use the SetFocus method to set focus from control1 to control2 and control2 to control3. Just let the TabIndex property manage that.

    Regardless, nothing seems to work in returning focus back to the app/form/control after the OutputTo action.

    Sorry, don't have a solution.

    Why are you doing backup to Excel anyway?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    AbbHeDa is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    4
    I very much appriciate you taking our time with this.
    This is the last part of an application, volontairy made, to a bird banding station. The people at the station trust pen and paper only and the only way I could convinse them to use a computor was to make a backup to excel after every record. Both to the HD and to a USB stick.
    I can now, with a good conscience say to them that it does not work.
    Now it's time to use a programmers most powerful tool the "work around".
    I will probable make a another backend database and send each record to both of them.
    Regards Henrik

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

Similar Threads

  1. Replies: 1
    Last Post: 02-29-2012, 09:38 AM
  2. Replies: 11
    Last Post: 01-26-2012, 01:22 PM
  3. DoCmd.OpenReport focus reverts back to form
    By shabbaranks in forum Programming
    Replies: 2
    Last Post: 01-07-2012, 06:18 PM
  4. SET focus back to TEXTBOX if validation does NOT pass
    By taimysho0 in forum Programming
    Replies: 5
    Last Post: 12-04-2011, 10:10 PM
  5. Replies: 0
    Last Post: 03-11-2010, 02:11 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