Results 1 to 7 of 7
  1. #1
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40

    Return to form from a modal form

    I enter the form "frmContactsMain" in order to add a record using this code.



    Code:
    DoCmd.BrowseTo acBrowseToForm, "frmContactsMain", , , , acFormAdd
    I enter the first and last name of the new contact. When leaving the last name field the event OnLostFocus searches for any records with those first and last names and displays those records in a new form frmChkDuplicates where Popup and Modal are set to yes.
    If I want to continue to add, my "Continue Add" button it closes the frmChkDuplicates and I returned to the next field in frmContactsMain form.

    My "Cancel Add" button is closes the form as well but I want to clear the fields (code not in the code below) and set the focus to the the first name. However, me.CfirstName.setfocus in bold below returns the error that I'm referring to a form that is closed.
    Ignore the Tempvars below.
    If it returns to the form with the ContinueAdd and allows me to continue at the next field, why doesn't it allow me to set focus.


    Code:
    Private Sub ContinueAdd_Click()
    
    
        'TempVars!AddNewContact = "Yes"
        DoCmd.CLOSE acForm, "frmChkDuplicates"
            
    
    
    End Sub
    
    
    Private Sub CancelAdd_Click()
    
    
        
        'TempVars!AddNewContact = "NO"
        DoCmd.CLOSE acForm, "frmChkDuplicates"
        Me.CFirstName.SetFocus
        
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Because Me.CFirstName is not on frmChkDuplicates (which is the one referred to by Me). Use Forms!frmContactsMain!CFirstName.SetFocus.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40
    Thank you Vlad,
    However, when added to the end of the CancelAdd_Click, that produced the same error.
    I'm trying to add the clearing and focus code to the next field gotfocus. It works, but I need to set a variable so that it only runs when I want it to.

    Jeff

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Can you please show us the code? And maybe a screen shot with the forms and the error?
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40
    I have figured out how to clear the first and last name fields and set the focus. The problem now lies in when the search for duplicates is triggered. I believe that the variable I use to trigger the search is not set correctly at different places in the code. I'm examining that now.
    If I still have a problem then I will work on getting the code.
    Thanks

  6. #6
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40
    Hello Vlad,
    Thanks for your willingness to help.
    I made so many changes in my code that it would be impossible to show them here, but I did get it working. The problem was where I set the variable TempVars!AddNewContact and where I tested it for "Yes" or "No". I also had to add another variable to show if I had pressed the Continue or Cancel button in the frmChkDuplicates.
    Thanks again.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 3
    Last Post: 02-17-2015, 10:25 AM
  2. Replies: 6
    Last Post: 01-06-2015, 12:37 PM
  3. Replies: 23
    Last Post: 07-05-2014, 08:13 AM
  4. Get Focus on Form after Modal Form closes
    By TinaCa in forum Programming
    Replies: 2
    Last Post: 09-06-2011, 04:47 PM
  5. passing variable from modal form to main form
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 06-03-2011, 05:34 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