• Creating field defaults from a previous field

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Creating field defaults from a previous field

    Author
    Topic
    #467723

    My database has the following fields, which are accessed by various forms.

    PostalAddress1
    PostalAddress2
    PostalSuburb
    PostalState
    PostalPostcode
    BusinessAddress1
    BusinessAddress2
    BusinessSuburb
    BusinessState
    BusinessPostcode

    What I would like to do is have the values of the Postal fields become the default for the Business fields to save typing when both addresses are the same. Is this possible? If so, How?

    Regards,
    Maria

    Viewing 1 reply thread
    Author
    Replies
    • #1215168

      You can’t quite do this default values, because default values are present before you do any data entry.

      There are three options I can think of.

        [*]Use the After Update event of each of Postal Address fields, to set the value of the corresponding Business address field. Perhaps only if it is null, so you don’t lose anything different you have already typed it.[*]Have a command button that copies all the Postal Address fields into the Business Address fields in one go.[*]Have another Yes/No field “Use Postal Address” . Then any queries that want a Business Address check the value of this Yes/No field. If it is Yes, the query just returns the Postal Address as the Business Address.
      • #1215172

        You can’t quite do this default values, because default values are present before you do any data entry.

        There are three options I can think of.

          [*]Use the After Update event of each of Postal Address fields, to set the value of the corresponding Business address field. Perhaps only if it is null, so you don’t lose anything different you have already typed it.[*]Have a command button that copies all the Postal Address fields into the Business Address fields in one go.[*]Have another Yes/No field “Use Postal Address” . Then any queries that want a Business Address check the value of this Yes/No field. If it is Yes, the query just returns the Postal Address as the Business Address.

        I would like to use the After Update event on the Postal Addresses to set the Business Address Fields, but I am not sure of how to code this correctly so that existing text is not overwritten.

        Using this method, would mean only minor changes to the existing database.

    • #1215174

      Here is one example, for PostalAddress1.
      There are a few situations to consider.

      The simplest option would be to only do this in new records. This simplifies initial data entry, but leaves updates to be done manually.
      Otherwise you need to think about…
      If BusinessAddress1 is currently the same as PostalAddress1, then presumably you want it to update to the new value?
      If you delete PostalAddress1, then do you want BusinessAddress1 deleted, if it is the same as what you have just deleted from Postaladdress1?

      Code:
      If me.NewRecord then
       me.BusinessAddress1 = me.PostalAddress1
      end if
      
      • #1215177

        Here is one example, for PostalAddress1.
        There are a few situations to consider.

        The simplest option would be to only do this in new records. This simplifies initial data entry, but leaves updates to be done manually.
        Otherwise you need to think about…
        If BusinessAddress1 is currently the same as PostalAddress1, then presumably you want it to update to the new value?
        If you delete PostalAddress1, then do you want BusinessAddress1 deleted, if it is the same as what you have just deleted from Postaladdress1?

        Code:
        If me.NewRecord then
         me.BusinessAddress1 = me.PostalAddress1
        end if
        

        Thanks John,

        That is exactly what I wanted – I have now added this to each of the Postal Address fields on the Data Entry Forms for new records. This will save having to type the same text twice when both addresses are the same. For existing records nothing should be changed automatically – all updates on existing records are done manually as needed.

        Regards,
        Maria

    Viewing 1 reply thread
    Reply To: Creating field defaults from a previous field

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

    Your information: