Saving a value if a form is closed while focus is still in the control

Ask a Question related to Microsoft Access, Design and Development.

  1. #1

    Default Re: Saving a value if a form is closed while focus is still in the control

    Strange. When I first tested it, the value was not saved. Now it seems to
    save when I close the form.

    How do you programmatically save the value for the selected control?
    (assuming it has been validated)?


    "Hugh O'Neill" <mail@hughoneill.co.uk> wrote in message
    news:bfiuv5$n4f$1@sparta.btinternet.com...
    > Tim Cali wrote:
    >
    > > I have a form with a 'Close' button. If focus is still on a textbox or
    > > combobox, and the close button is pressed, the form will close without
    > > saving data. How can I get the last-entered value to save if somebody
    > > doesn't know that they have to exit the control for Access to know to
    > > save the value?
    > >
    > > As a workaround, I set focus to some other control in the form, which
    > > seems to work, however if the little 'x' in the form is pressed, I'll
    > > run into that problem again. How can I guarantee to save the last
    > > entered value if somebody closes the form?
    > >
    > > I suppose I could set focus to another control on the Form_Close
    > > event, but that seems odd.
    > >
    > > Thanks.
    >
    >
    > If the Form is bound to its record source, then closure will save the
    > current record automatically. If you wish to ensure the record entries
    > are complete, you will need to write code to test and validate each
    > entry text box. Then only enable your 'Close' button if the testing
    > proves True. To remove the 'X' close box, chage the form border type
    > to, say, Dialogue.
    >
    > hth
    >
    > Hugh

    Tim Cali Guest

  2. Similar Questions and Discussions

    1. Taking focus from a control
      In my app, I have a DataGrid, and when a row is double-clicked, a new view is put up showing the data. I also add eventListeners to the stage for...
    2. Flash form focus
      Is there a way to establish the focus on a specific field (at page load) using the new MX7 Flash forms?
    3. focus/lost focus of custom control
      Hi new to .NET and have a question. What I want to do if have a custome control (contains a table grid of text boxes) and multiple instances...
    4. Control focus
      Hi guys, How to Focus a TextBox on page load? I have this function: public static void FocusControl(Page pagina, WebControl control) {...
    5. Which control had focus before postback?
      Hi, Is it possible to retrieve the control that had the focus when the page was posted back? Because the focus is lost when a postback occurs...
  3. #2

    Default Re: Saving a value if a form is closed while focus is still in the control

    Tim Cali wrote:
    > Strange. When I first tested it, the value was not saved. Now it
    > seems to save when I close the form.
    >
    > How do you programmatically save the value for the selected control?
    > (assuming it has been validated)?
    >
    >
    > "Hugh O'Neill" <mail@hughoneill.co.uk> wrote in message
    > news:bfiuv5$n4f$1@sparta.btinternet.com...
    > > Tim Cali wrote:
    > >
    > > > I have a form with a 'Close' button. If focus is still on a
    > > > textbox or combobox, and the close button is pressed, the form
    > > > will close without saving data. How can I get the last-entered
    > > > value to save if somebody doesn't know that they have to exit the
    > > > control for Access to know to save the value?
    > > >
    > > > As a workaround, I set focus to some other control in the form,
    > > > which seems to work, however if the little 'x' in the form is
    > > > pressed, I'll run into that problem again. How can I guarantee to
    > > > save the last entered value if somebody closes the form?
    > > >
    > > > I suppose I could set focus to another control on the Form_Close
    > > > event, but that seems odd.
    > > >
    > > > Thanks.
    > >
    > >
    > > If the Form is bound to its record source, then closure will save
    > > the current record automatically. If you wish to ensure the record
    > > entries are complete, you will need to write code to test and
    > > validate each entry text box. Then only enable your 'Close' button
    > > if the testing proves True. To remove the 'X' close box, chage the
    > > form border type to, say, Dialogue.
    > >
    > > hth
    > >
    > > Hugh

    Saving the value of a single control doesn't really mean anything in a
    database as the value of a bound control will normally be just one
    element of the whole record. Normally you save the Record. As I said,
    this is done automatically by Access when you close the Form or when
    you move from the current Record or Form. If you want to save the
    changed Record programatically at some other point, then you can use
    the following code to do this:

    If Me.Dirty then Me.Dirty = False

    in, say the click event of a 'Save' button.

    What this does is as follows:

    As you create a new Record or change a value in an existing one, the
    Dirty property is set to True - the Record is 'Dirty'. Setting the
    Dirty property to False, forces the Record to be saved in order that
    the Dirty property can actually be False as you have told it to be.

    hth

    Hugh
    Hugh O'Neill Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139