Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    DoCmd.Close acForm not Working (2003 SP3)

    What am I doing wrong here? This code does not close my form frmYearEndReports. This form has 2 unbound fields where I insert a beginning date and ending date for reports and I want it to close as soon as the report itself is opened.

    Private Sub Form_LostFocus()
    DoCmd.Close acForm, "frmYearEndReports", acSaveYes

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: DoCmd.Close acForm not Working (2003 SP3)

    You cannot close a form in its own On Lost Focus event.

    Do you have a command button on the form to open the report? If so, put the instruction to close the form in the On Click event of the command button.

    Note: acSaveYes will cause the design of the form to be saved (not the current record, that will be saved automatically). In most situations, there is no need to use acSaveYes.

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: DoCmd.Close acForm not Working (2003 SP3)

    This form actually opens 5 different reports off of 5 different command buttons. I will change that code to close off of the command button. Thanks.

  4. #4
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DoCmd.Close acForm not Working (2003 SP3)

    Another possible approach.

    Because I wanted the user to go directly to the report after selecting the print criteria and not have to click on a button, which would involve their having to think and use a mouse, I did the following:

    On exiting from the parameter box:

    Private Sub txtRangeEnd_01_Exit(Cancel As Integer)
    '
    ' data selection lines go here
    '
    DoCmd.OpenReport "rpt 01 LogIn - Label", acViewPreview, , strWhere
    DoCmd.RunCommand acCmdZoom100
    ' the next line removes the focus from the data field to a dummy box
    Me.txtDoNotDelete.SetFocus
    Exit Sub

    The following code on closing the report after printing, closes the original form and sends them off to the next one. Minimal thinking and manual dexterity needed.

    Private Sub Report_Close()
    DoCmd.Close acForm, "frm 01 CN - 02 - Login - Labels"
    DoCmd.OpenForm "frm 01 CN - 01 - Login", , , Maximize
    End Sub


    Not very pretty, but it works for me,
    Cheers,
    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •