Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Values 1

Status
Not open for further replies.

HighLightUK

Technical User
Mar 4, 2003
20
GB
Can I make the default value of a textbox on a form equal to the value displayed in another textbox?

i.e if textbox1 value is 0 on the form, then the default value for textbox2 = 0, but if textbox1 = 7, then textbox2 default value = 7.

There are only two possible values in textbox1. I want textbox2 to update its control source table with this value. I tried using an IIf statement but couldn't get it to work.
 
Default values are the values that a NEW record starts out with. It is not the default value after the user enters something into a control on a form. So, if you want field2 to have the value of the data entered into field1 then use the following VBA code in the After Update event procedure of Field1:
me![field12] = me![Field1]
This way they will always be in sinc.

Hope this helps. Bob Scriver
 
Yes, I do know this only applies to new values.

Essentially, these two textboxes are hidden from the user. Textbox1 holds user defined info specified elsewhere in the database. This is the master field.

Textbox2 drives a pricing markup and is derived from the master. Once per year however, the master fields will be updated and I didn't want to change anything entered in the previous year.

Your code does work fine if I put it into the AfterUpdate event of a user entered field, but if the user ever went back and changed the field AFTER the master update, the pricing would go out of sync (this should be very unlikely however).

I wanted to drive the update of the table from default values because this only applies to new records.

Thankyou very much for the help Bob.
 
Okay, I understand I think. Are you going to update Text1 with a value from a table? At what point are you going to do this? Is that value being derived from a query column that is the Control Source for new records? Just how is that data getting assigned to that bound control? The reason I am asking because it is at that time that we update the text2 control just during the New Record creation. I am just trying to ascertain how you are doing it now. Bob Scriver
 
Hi Bob,

Text1 is updated from a table via the Query which sits behind the subform. Text1's control source is set to this table where the master info is stored.

Text2 ONLY needs updating when a new record is added to the subform. Currently, its control source is set to a Markup field in the table behind the subform.

There can only be two values, either 7.69 or O.

Basically, the user enters a code (which pulls all of the descriptive and pricing info onto the form) and a quantity, then this info is updated onto the underlying table (along with the Markup value).
 
You can use the IIF function in the Default property of Text2 for this.
Example:
IIF( [Text1] = 0 , 0, 7.69)

Now these numbers might not be right but it works like this. If text1 = 0 then text2 = 0 else text2 = 7.69. You make the modifications to make the right data assignments. This will only happen on new records. Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top