Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pop up form (2003)

    I have the following code behind a command button on a form:

    Private Sub CmdClientData_Click()
    On Error GoTo ErrorHandler
    Dim strDocName As String
    Dim strLinkCriteria As String
    strDocName = "tblSFFrm"
    strLinkCriteria = "[SFID]=" & Me![Combo80]
    DoCmd.OpenForm strDocName, , , strLinkCriteria
    ErrorHandlerExit:
    Exit Sub
    ErrorHandler:
    MsgBox "Error No: " & Err.Number & ";Description: " & Err.Description
    Resume ErrorHandlerExit
    End Sub

    When you click the command button, it opens a form but closes the form that the comman button is on. Is there a way to keep the main form open or once the pop up form is closed to go back to the main form?

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

    Re: Pop up form (2003)

    The procedure you posted does not contain code to close the original form. Perhaps there is code in tblSFFrm that closes the original form?

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pop up form (2003)

    New scenario. The form that has the popup form now stays open but it unmaximizes. When I open the main form, I have some code so that the form is maximized when opened. Now when you click on the button to open the popup form, it demaximizes the form so that you have to manually maxamize it once the popup form closes. Is there any way to keep the main form maximized once the popup form closes? Any help would be appreciated.

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

    Re: Pop up form (2003)

    There is no a priori reason why the calling form should be restored when it opens the popup form. Do you have code that restores the form when it is deactivated?

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Pop up form (2003)

    What you could do is to make the main form as large as possible, then there's no need to worry about maximising and re-maximising this form.

  6. #6
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Salem, Oregon, USA
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pop up form (2003)

    I used to do what Patt does, but finally got familiar with "docmd.restore" in the "on-activate" or on-focus events --
    Another trick I use is to send the name of the calling form, or the form you want to return to, as an openarg to the called form. That way, when the called form closes, you can "docmd.selectobject acform ... " etc, and return directly to the calling form.

    thx
    Pat

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pop up form (2003)

    I used your suggestion (Another trick I use is to send the name of the calling form, or the form you want to return to, as an openarg to the called form. That way, when the called form closes, you can "docmd.selectobject acform ... " etc, and return directly to the calling form.) and it works fine. I put the following in the close button on the popup form:
    DoCmd.Close
    DoCmd.SelectObject acForm, "frmepentry2"
    DoCmd.Maximize

    I am not real savey with VBA syntax, so when I got this to work I was happy. Thanks for the tip.....

  8. #8
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error handling

    Another problem: When someone clicks on the popup form button and there wasn't a selection made in the combo box that it is attached to, they get the following error: Error No:3075,Description: Syntax error (missing operator) in query expression '[SFID]='

    What code can I add to the code in the original post to handle this kind of error? Thanks for your help.

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

    Re: Error handling

    The best way is to test before trying to open the popup form:

    If IsNull(Me!Combo80) Then
    MsgBox "Please select an item!", vbExclamation
    Me.Combo80.SetFocus
    Exit Sub
    End If
    strDocName = "tblSFFrm"
    ...

  10. #10
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error handling

    Thanks Hans - works perfectly.

Posting Permissions

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