Default values in a form need to populate another field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clloyd
    New Member
    • Mar 2008
    • 91

    Default values in a form need to populate another field

    I thought I posted this earlier but must have not completed it.

    I have a field Status that I have a default value on of Open when a user adds a new record. This is an older form and I just added the default to avoid people leaving it blank. This same field also populates another field based on the selection they make in the field Status.

    My problem now is if the user keeps the default (does not change it to another selection or does not manually change it to open) it does not populate the other field.

    Anyone have any suggestions.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You need to call the event that does the calculation from the Form_Current event if the record is a new record.

    For instance, say you have a field called Field1, with its Default Value set to 100. In its AfterUpdate event you use a calculation

    Me.Field2 = Me.Field1 * 5

    to assign a value to Field2.
    Code:
    Private Sub Field1_AfterUpdate()
      Me.Field2 = Me.Field1 * 5
    End Sub
    To make sure this calculation is done if the Default Value is retained, you'd need this
    Code:
    Private Sub Form_Current()
    If Me.NewRecord Then
      Field1_AfterUpdate
    End If
    End Sub
    When a new record is created, Field2 will be assigned the value of 500. If the value of Field1 is changed, the value of Field2 will also be changed.

    Linq ;0)>

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Your duplicate posting of this question/problem has been deleted! Please refrain from this prohibited behavior in the future.

      From FAQs

      Do Not Double Post Your Questions

      Double posting is where you start a thread on a topic and then for some reason start another thread on exactly the same topic in the same forum. Please do not do this because

      1. It makes it very hard for people to answer you especially if there are answers happening in all the threads you have started because they have to read 2 or more threads in order to see what has already been said.
      2. It swamps the forum with your problem resulting in less attention for the other threads.

      If you feel for some reason that you post has been overlooked (for instance it hasn't had any replies) please do not repost the question. Post a message to the thread you started, this will bump it back to the top of the thread list for the forum.


      Thank you for your attention in this matter.


      Linq ;0)>

      Moderator

      Comment

      • clloyd
        New Member
        • Mar 2008
        • 91

        #4
        Please read my first line:

        I thought I posted this earlier but must have not completed it.

        It was an accident. I would never double post on purpose.

        Comment

        • clloyd
          New Member
          • Mar 2008
          • 91

          #5
          I already have code that does all this the problem is if you accept the default and don't change anything the code does not work. If I manually change the default it works fine and populates the other field. Am I understanding your response or am I missing a step.

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            You're missing a step! How are you assigning a value to the second field? Normally this would be done in the AfterUpdate event of the first field, and the fact that this doesn't work when the Default Value is retained tends to support this supposition. We need to see your code including the sub header.

            Linq ;0)>

            Comment

            • clloyd
              New Member
              • Mar 2008
              • 91

              #7
              Code:
              Private Sub Substatus_AfterUpdate()
                  Me.Status = Stat(Me.SubStatus.Value)
                  
              End Sub
              This is my after update code.

              Comment

              • clloyd
                New Member
                • Mar 2008
                • 91

                #8
                I still have not resolved this. Does anyone have any ideas?

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  Code:
                      Private Sub Form_Current()
                      If Me.NewRecord Then
                        SubStatus_AfterUpdate
                      End If
                      End Sub
                  Linq ;0)>

                  Comment

                  • clloyd
                    New Member
                    • Mar 2008
                    • 91

                    #10
                    It did not populate the other field. Thanks though.

                    Comment

                    Working...