By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

Default values in a form need to populate another field

P: 93
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.
Sep 19 '08 #1
Share this Question
Share on Google+
9 Replies


missinglinq
Expert 2.5K+
P: 3,532
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Field1_AfterUpdate()
  2.   Me.Field2 = Me.Field1 * 5
  3. End Sub
To make sure this calculation is done if the Default Value is retained, you'd need this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me.NewRecord Then
  3.   Field1_AfterUpdate
  4. End If
  5. 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)>
Sep 19 '08 #2

missinglinq
Expert 2.5K+
P: 3,532
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
Sep 19 '08 #3

P: 93
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.
Sep 19 '08 #4

P: 93
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.
Sep 19 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
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)>
Sep 19 '08 #6

P: 93
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Substatus_AfterUpdate()
  3.     Me.Status = Stat(Me.SubStatus.Value)
  4.  
  5. End Sub
  6.  
  7.  
This is my after update code.
Sep 22 '08 #7

P: 93
I still have not resolved this. Does anyone have any ideas?
Oct 3 '08 #8

missinglinq
Expert 2.5K+
P: 3,532
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Form_Current()
  2.     If Me.NewRecord Then
  3.       SubStatus_AfterUpdate
  4.     End If
  5.     End Sub
  6.  
Linq ;0)>
Oct 3 '08 #9

P: 93
It did not populate the other field. Thanks though.
Oct 6 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.