Results 1 to 3 of 3
  1. #1
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    Get Focus on Form after Modal Form closes

    I gave the user the ability to open a form in modal to put in information about a change on the main (non modal) form.

    The modal form displays when the user updates a combo box.

    The problem is, when the click the Cancel the button on the modal form I want do an undo on the main form to reset the data back the way it was before the update on the combo box.

    I have tried using a public variable to indicate the form needs to be refreshed. The problem is I can't get the focus back to the main form. Any suggestions. Existing code below (a bit messy as I keep fudging with it).

    Open the modal form
    Private Sub cboWorker_AfterUpdate()

    DoCmd.OpenForm "frmWorkerChangesMod"

    End Sub

    go to the public sub (the variable are declared elsewher)

    Private Sub cboWorker_BeforeUpdate(Cancel As Integer)
    wrkrid = Me.cboWorker.Column(0)
    NotSaved = 2
    Call fldUndo(wrkrid, NotSaved)

    End Sub

    The public sub

    Public Sub fldUndo(wrkrid, NotSaved)
    If NotSaved >= 1 Then


    Forms![frmCompanyInformatino]![CompanyCrewMember] = wrkrid
    End If
    DoCmd.Close acForm, "frmWorkerChangesMod"

    End Sub

    Any suggestions would be appreciated

  2. #2
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87
    I got it to work. I had to put the public sub in both the main form and the modal form. Then I was able, at the end of the public sub in the modal, to close the modal and use the docmd.runcommand acCmdUndo.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Okay, this is a bit strange. You have a Before Update and an After Update event for the cboWorker combo box. But the way this is set up, it can't logically be the same combo box that you are referring to. Do you have a combo with the same exact name on the modal form which is opening?

    Remember that the before update happens before the after update.

    EDIT: Nevermind, it appears you got it to work the way you needed it to.
    Last edited by boblarson; 09-06-2011 at 04:48 PM. Reason: Never mind

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

Similar Threads

  1. Modal Form Operator
    By mm07nkb in forum Forms
    Replies: 5
    Last Post: 09-01-2011, 10:53 AM
  2. passing variable from modal form to main form
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 06-03-2011, 05:34 PM
  3. Replies: 1
    Last Post: 02-17-2011, 06:23 AM
  4. Form closes after mssage box
    By liam01752 in forum Programming
    Replies: 1
    Last Post: 12-06-2010, 03:30 PM
  5. Change to Form Closes Access
    By jbhjm in forum Forms
    Replies: 5
    Last Post: 04-22-2009, 01:04 PM

Tags for this Thread

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