• automatic field entry (2002)

    Author
    Topic
    #408767

    I’ve done this before but I can’t remember the coding.
    I am entering data in a form. First field is StudID.
    I finish one row of data and want to go to the next record and have the same StudID as the previous record automatically placed in the new record.
    How do I code it to do this.

    Thanks

    Paul

    Viewing 7 reply threads
    Author
    Replies
    • #865994

      The best way I’ve found is to move the value of StudID into the DefaultValue. You can do this in either the AfterUpdate event of the StudID control or in the form’s AfterUpdate event. You need to be careful if StudID is text rather than numeric, as you need to include the quotes. Assuming your controlname is txtStudID, you’d use either of these:

      txtStudID.DefaultValue = txtStudID ‘if numeric
      or
      txtStudID.DefaultValue = chr(34) & txtStudID & chr(34) ‘ if text

    • #865995

      The best way I’ve found is to move the value of StudID into the DefaultValue. You can do this in either the AfterUpdate event of the StudID control or in the form’s AfterUpdate event. You need to be careful if StudID is text rather than numeric, as you need to include the quotes. Assuming your controlname is txtStudID, you’d use either of these:

      txtStudID.DefaultValue = txtStudID ‘if numeric
      or
      txtStudID.DefaultValue = chr(34) & txtStudID & chr(34) ‘ if text

    • #865996

      Manually: type Ctrl+’ (apostrophe) in the field in the new record.

      Automatically: see How to fill record with data from previous record automatically in Access 2000 (also applies to Access 2002 and later)

    • #865997

      Manually: type Ctrl+’ (apostrophe) in the field in the new record.

      Automatically: see How to fill record with data from previous record automatically in Access 2000 (also applies to Access 2002 and later)

    • #866310

      Just an added comment about Mark’s default value suggestion. One handy, yet sometimes overlooked, advantage of setting a default value, instead of setting the actual value, is that a default value will display to the user, BUT WILL NOT enter data in the table, until other fields are used. As an example, if Joe User opens your form, enters one record, then moves to a new record, if Joe decides he doesn’t want to enter that record, he’ll just close the form. If you have used code to set the value (not default value) of the field, then you either end up with a partially empty record, with just the ‘automated’ fields filled in, OR if you have data validation in place/required fields, Joe User will get prompts when trying to close the form, because a record was created, but not completed.

      On the other hand, if you have your code set the default value, and Joe User closes your form after going to a new record, no ‘partially empty’ records are created, nor does Joe User get any data validation prompts.

      I post this once in a while, when I see this type of topic arise, because I’ve been the Joe User too many times, who was plagued with message boxes when I just wanted to close a form! grin

    • #866311

      Just an added comment about Mark’s default value suggestion. One handy, yet sometimes overlooked, advantage of setting a default value, instead of setting the actual value, is that a default value will display to the user, BUT WILL NOT enter data in the table, until other fields are used. As an example, if Joe User opens your form, enters one record, then moves to a new record, if Joe decides he doesn’t want to enter that record, he’ll just close the form. If you have used code to set the value (not default value) of the field, then you either end up with a partially empty record, with just the ‘automated’ fields filled in, OR if you have data validation in place/required fields, Joe User will get prompts when trying to close the form, because a record was created, but not completed.

      On the other hand, if you have your code set the default value, and Joe User closes your form after going to a new record, no ‘partially empty’ records are created, nor does Joe User get any data validation prompts.

      I post this once in a while, when I see this type of topic arise, because I’ve been the Joe User too many times, who was plagued with message boxes when I just wanted to close a form! grin

    • #866324

      One more way to do this kind of thing – and we use it frequently – is to use a subform, so that the StudID is automatically picked up from the main form. It will often work in such situations.

    • #866325

      One more way to do this kind of thing – and we use it frequently – is to use a subform, so that the StudID is automatically picked up from the main form. It will often work in such situations.

    Viewing 7 reply threads
    Reply To: automatic field entry (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: