Controlled Close with the "x" button and subform - is it hopeless?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kelii

    Controlled Close with the "x" button and subform - is it hopeless?

    I've been beating my head against this problem for the last several
    days, and I haven't found a decent solution yet. So I'm turning to the
    group for some moral support or better yet some answers.

    Background:
    I want the user to be able to close the form by using the "x" button
    in the window title bar, I do not want to disable this. I have found a
    nice solution in the Access Developer's Handbook that disables the
    "x", however I am hoping to avoid using this solution since I like
    having the "x" available to the user.

    The form that needs the Controlled Close has a subform in datasheet
    view; the subform is linked to the main form using the primary /
    foreign key.

    My question:
    Under this scenario, has anybody made the controlled close to work? If
    so, what is the general coding strategy?

    I've gone through several iterations of code, here is a mock up of
    where I've ended; btw it doesn't work very well, several errors result
    in akward form handling.

    Form_Load
    'Nothing here related to controlled close

    Form_Current
    'Nothing here either

    Form_BeforeUpda te
    'Check for empty form
    'If empty, exit sub
    'Validate form
    'If invalid Cancel = True, Exit Sub

    Form_Unload
    'Call Form_BeforeUpda te
    'If invalid form then Cancel = True
    'Repopulate form with user input
    'Exit Sub

    Function ValidateForm
    'Check for empty form
    'Various error checking
    'Check for empty subform (note: user cannot access subform until all
    required fields in
    'parent form are completed
    'Various error checking
    'If invalid, returns False and sets mod variable strError to text
    describing error

    Form_Error
    'If incomplete form error (2169) then
    'Msgbox allow user to Save ('yes'), Not Save ('no'), or Cancel close
    ('cancel')
    'If user wants to continue editing current record, then
    'Prompt user with error msg from mod variable strError
    'And set variables up to repopulate form with user input in Form_Unload
  • The Frog

    #2
    Re: Controlled Close with the "x&quot ; button and subform - is ithopeless?

    Hi Kelii,

    Just a passing thought, but perhaps the answer is to make the form
    'borderless' (thin) and maybe modal. Then inside your form you add
    your own [x] and title bar etc so that it 'looks' like the form you
    desire. The difference here would be that the [x] is actually a
    command button that you can assign code to.

    The Frog

    Comment

    • Kelii

      #3
      Re: Controlled Close with the "x&quot ; button and subform - is ithopeless?

      Frog,

      Thanks for the suggestion. I just can't bring myself to do as you
      suggest to the form. Not to be offensive, but it seems worse than
      disabling the 'x' altogether. I keep thinking that all the other
      commercial apps can do it, so why can't I?

      Anyhow, I stumbled on a decent work around. I'd love to give the guy /
      gal credit, but I can't seem to find the link again. Anyway here goes:

      Main form
      Declarations area:
      'Setup a series of variables that can store the user's input (e.g.,
      strDescription, sglQuantitiy)
      'Setup variable indicating close is ok (e.g., strOkToClose,
      blnOkToClose)

      Form_BeforeUpda te
      'Check for emtpy form, if so exit
      'Validate form, if invalid Cancel = True, exit (this generates your
      Form_Error)

      Form_Unload
      'Check if ok to close
      'If not ok to close then restore input using variables from
      declarations area
      'Empty variables

      Form_Error
      'In addition to others, select case for DataErr 2169
      'Prompt user for option to exit without save or cancel exit
      'If exit without save, do so
      'If exit with save, set variable to users input for restore in
      Form_Unload

      Subform:
      Form_BeforeUpda te
      'Various bits of code to validate input

      That's it! Pretty simple. The only drawback is that in my design, you
      get two prompts when you attempt to close using the 'x' and the data
      in the form or subform is not valid. First you get the error prompt
      from the Form_BeforeUpda te, then you get another prompt that asks if
      you want to continue. In a perfect world, one could condense this into
      one prompt; however I have not been able to do so.

      Kelii

      Comment

      • Roger

        #4
        Re: Controlled Close with the "x&quot ; button and subform - is ithopeless?

        On Jun 2, 10:22 am, Kelii <kel...@yahoo.c omwrote:
        I've been beating my head against this problem for the last several
        days, and I haven't found a decent solution yet. So I'm turning to the
        group for some moral support or better yet some answers.
        >
        Background:
        I want the user to be able to close the form by using the "x" button
        in the window title bar, I do not want to disable this. I have found a
        nice solution in the Access Developer's Handbook that disables the
        "x", however I am hoping to avoid using this solution since I like
        having the "x" available to the user.
        >
        The form that needs the Controlled Close has a subform in datasheet
        view; the subform is linked to the main form using the primary /
        foreign key.
        >
        My question:
        Under this scenario, has anybody made the controlled close to work? If
        so, what is the general coding strategy?
        >
        I've gone through several iterations of code, here is a mock up of
        where I've ended; btw it doesn't work very well, several errors result
        in akward form handling.
        >
        Form_Load
        'Nothing here related to controlled close
        >
        Form_Current
        'Nothing here either
        >
        Form_BeforeUpda te
        'Check for empty form
        'If empty, exit sub
        'Validate form
        'If invalid Cancel = True, Exit Sub
        >
        Form_Unload
        'Call Form_BeforeUpda te
        'If invalid form then Cancel = True
        'Repopulate form with user input
        'Exit Sub
        >
        Function ValidateForm
        'Check for empty form
        'Various error checking
        'Check for empty subform (note: user cannot access subform until all
        required fields in
        'parent form are completed
        'Various error checking
        'If invalid, returns False and sets mod variable strError to text
        describing error
        >
        Form_Error
        'If incomplete form error (2169) then
        'Msgbox allow user to Save ('yes'), Not Save ('no'), or Cancel close
        ('cancel')
        'If user wants to continue editing current record, then
        'Prompt user with error msg from mod variable strError
        'And set variables up to repopulate form with user input in Form_Unload
        not sure what you mean by 'controlled close'
        you have form A containing a subform B
        and the user clicks 'x'
        if subform B is dirty, what should happen ?
        if form A is dirty, what should happen ?

        Comment

        Working...