Results 1 to 10 of 10
  1. #1
    Jimjr is offline Novice
    Windows 11 Access 2019
    Join Date
    Jun 2024
    Posts
    6

    Button to close a form+report preview

    I have one continuous form with a search feature. When a hyperlink field is clicked, a second form with a sublist opens. There is a button "cmdReset" to close the second form, that has been working correctly.


    I added a button to preview a report and want the cmdReset button to close both the form and the report. For some reason it has to be clicked twice to work. I've tried different things including changing the order of the 2 objects closing.
    TIA for any help.
    Code:
    Private Sub cmdReset_Click()
        'GROUP FORM
        'Purpose: Clear all the search boxes in the Form Header, and show all records again.
        Dim ctl As Control
    
    
        'Clear all the controls in the Form Header section.
        For Each ctl In Forms![AKAListForm].Section(acHeader).Controls
            Select Case ctl.ControlType
            Case acTextBox, acComboBox
                ctl.Value = Null
            Case acCheckBox
                ctl.Value = False
            End Select
        Next
    
    
        'Remove the form's filter.
        Forms![AKAListForm].FilterOn = False
          
        DoCmd.Close acReport, "AKAGroupRpt"
        DoCmd.Close acForm, "AKAGroupForm"
        
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,285
    Walk your code with F8 amd see what happens.
    Move the close report to before the ctrl loop, experiment like that.

    Code looks OK to me?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Jimjr is offline Novice
    Windows 11 Access 2019
    Join Date
    Jun 2024
    Posts
    6
    I did the debug and found that the first click of cmdReset doesn't go into cmdReset_Click() at all! I guessed that moving the focus to the report preview takes the power or something away from the buttons on the form.


    So I added OpenForm AKAGroupForm to the openReport macro, and that fixes it EXCEPT if you click the report preview, say to print it, it goes back to doing nothing except bringing the top command ribbon down.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,285
    No,
    You need to set focus first to the form, then the button.
    So the first click is just setting focus back to the form. If you click it again then the event will run.

    Standard windows processing.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Jimjr is offline Novice
    Windows 11 Access 2019
    Join Date
    Jun 2024
    Posts
    6
    Ok, thanks

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I tested with an open report and form. When I click on the report, then mouse over the form close button, the button mouseover highlight takes effect, indicating the button should work - which it does. The form closes.

    There may be something about one or more of your form properties that are preventing it from working this way. I don't suppose your cf form is a subform and your buttons are on the subform? Consider posting a db copy (copy/compact, repair/zip and post here).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Jimjr is offline Novice
    Windows 11 Access 2019
    Join Date
    Jun 2024
    Posts
    6
    No, it's not a subform. When I mouseover the button after clicking the report, it does show the highlight but does not work.

  8. #8
    Jimjr is offline Novice
    Windows 11 Access 2019
    Join Date
    Jun 2024
    Posts
    6
    You said the form closes. Do you mean both the form and report close?

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    No, but I will try that in case it makes a difference.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Private Sub cmdClose_Click()
    DoCmd.Close
    DoCmd.Close acReport, "EmployeeInfo"
    End Sub
    I open form and report, click on report (a row gets highlighted so I know that report is active), click on form button, both close.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Main/sub form close with Close button fail
    By twgonder in forum Forms
    Replies: 5
    Last Post: 03-22-2024, 02:53 PM
  2. Button showing up in report print preview
    By ahuffman24 in forum Access
    Replies: 3
    Last Post: 05-29-2019, 09:53 AM
  3. Replies: 1
    Last Post: 04-13-2017, 02:37 PM
  4. Replies: 3
    Last Post: 07-11-2013, 11:52 AM
  5. Replies: 2
    Last Post: 05-11-2012, 11:52 AM

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