Results 1 to 6 of 6
  1. #1
    bgephart is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2012
    Posts
    15

    GoToControl and SetFocus question

    I have an information form that is set to open "AfterUpdate" of the Book ID control on my original Checkout Form. This part I have working well at this point. However, on the information form, which basically serves to double-check what was entered in "Book ID", I have Yes and No buttons. The Yes button I have set to close the information form, return to Checkout Form at set focus on another field down the form. The No button I would like to set to return to the Book ID control, but it won't seem to do that. Is that because the original procedure is connected to "AfterUpdate"?



    Here's the code in place for the two buttons:
    Code:
    Private Sub Close_Yes_Click()
    On Error GoTo Err_Close_Yes_Click
    
        If Me.Dirty Then Me.Dirty = False
        Forms![Checkout Form]![OutDate].SetFocus
          
        
        DoCmd.Close
    Exit_Close_Yes_Click:
        Exit Sub
    Err_Close_Yes_Click:
        MsgBox Err.Description
        Resume Exit_Close_Yes_Click
        
    End Sub
    Private Sub No_Button_Click()
    On Error GoTo Err_No_Button_Click
    
        If Me.Dirty Then Me.Dirty = False
        Forms![Checkout Form]![Book ID].SetFocus
        DoCmd.Close
    Exit_No_Button_Click:
        Exit Sub
    Err_No_Button_Click:
        MsgBox Err.Description
        Resume Exit_No_Button_Click
        
    End Sub
    .

    My other instance is very similar, except that I'm trying to use a macro to do basically the same thing. In the original macro that is opening the information form (running "AfterUpdate" of Book ID), I'm opening a message box if the Book ID is not found in the database at all (as opposed to the wrong one that would still bring up a record), and would like to return to the Book ID control after the message box is closed. In both cases, the control always returns to the control that comes after the Book ID control. Same problem?

    If so, how do I do this?

    Thanks for your help. You guys are great!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    What is error message?

    Might be better to use BeforeUpdate event.
    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
    bgephart is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2012
    Posts
    15
    Quote Originally Posted by June7 View Post
    What is error message?

    Might be better to use BeforeUpdate event.
    There is no error message. I just can't get the focus back to the Book ID field where I want it.

    BeforeUpdate wouldn't work because all of this depends on what is typed into the Boko ID field.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Is this BookID control an unbound control? Is it a textbox? Why not a combobox?

    Shouldn't the BeforeUpdate event serve to check if BookID is even in the db? If not in db, the update action will cancel and the AfterUpdate to open form will not trigger. The issue is when BookID is in db and the Information form opens. Why open an independent form? Could just display the related book info on the Checkout form.

    I had a similar issue. I wanted focus to always return to a combobox after item selected. It is the last data entry control on a form and it is unbound. Multiple items will be selected (one at a time) and a record saved into two tables. I had to create a locked control that would receive focus after each selection. Code in GotFocus event of the locked control sets focus back to the combobox. Fortunately, I needed the locked control anyway because it is a listbox displaying information that is dependent on selection in combobox.
    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
    bgephart is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2012
    Posts
    15
    Okay, so I got the second instance to work - the one where I was using the macro - by adding a "CancelEvent" in there and putting the macro on BeforeUpdate of the Book ID control, as you suggested.

    I can't put everything on one form because the linked Excel table cannot be edited, and when I add fields from it to a query, it makes the recordset uneditable as well. At least that's the way I'm reading the error messages, and what seems to be happening.

    So, I still have a popup Book Information form that is triggered "AfterUpdate" of the Book ID form to make sure the right number has been entered. These are the numbers that do show up in the Excel table, and the information pops up on the form. And this is what I was using the VBA code for, which was mostly created using the Button Wizard, but which I added the SetFocus lines to.

    When I put that whole process in BeforeUpdate, I got error messages saying I had to save the control before I could use SetFocus. So, I've put it back on AfterUpdate. I've tried using Undo as well instead of and in addition to SetFocus, and have had no luck at all. How do I get the focus back on Book ID after I press the No button on my popup form? It continues to go to the next field. I'm having no problem with the Yes button taking the focus to another field, and I've checked my typing over and over!

    Any more thoughts?

    Thanks -

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Think I encountered this same frustration and that was why I had to devise alternate solution as described in my previous post.

    I don't understand why can't show the data on one form. Instead of popup form, make it a subform or a listbox on the first form.
    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.

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

Similar Threads

  1. simple SetFocus
    By markjkubicki in forum Forms
    Replies: 5
    Last Post: 10-04-2011, 11:47 AM
  2. Help with gotocontrol, activecontrol
    By k9drh in forum Forms
    Replies: 5
    Last Post: 04-21-2011, 10:12 AM
  3. SetFocus Problem
    By ColPat in forum Programming
    Replies: 2
    Last Post: 06-21-2010, 04:43 AM
  4. Issues with DoCmd.GoToControl
    By RaMcHiP in forum Programming
    Replies: 1
    Last Post: 05-09-2009, 08:56 PM
  5. SetFocus Issue
    By Sinjin in forum Access
    Replies: 0
    Last Post: 02-14-2008, 07:31 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