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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value in tables 1

Status
Not open for further replies.

ThomasJF

Technical User
Apr 25, 2000
6
NO
Hello!<br>I have a problem doing the following:<br>In a table, I would like to set the default value in a field equal to an other field in the same table (date). <br>Is there any way i can do this? <br><br>Thanks for any help<br><br>Best regards,<br>Thomas Fyhn<br>
 
In the AfterUpdate event of Date1:<br><br>If IsNull(Me.Date2) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Me.Date2 = Me.Date1<br>End If<br><br>
 
Thank you for the answer, but I am a bit slow, so could you please explain the following:<br>1. Do I use the expression builder or the code builder? Is there any difference?<br>2. the &quot;Me.Date&quot; is that where you put
.[field]?<br><br>Thanks again :)<br><br>-Thomas Fyhn
 
1. code builder. you can't use VBA code in an expression, things like if...end, do until, etc. sometimes there are substitutes available such as &quot;iif&quot;. See help on &quot;expression&quot;.<br>2. Me is a valid VBA shortcut for &quot;the current form's name&quot;. Substitute your actual field names for Date1 and Date2.
 
Thomas,<br>Just to be clear, you can't set the default value that way for the 'Table' itself, only in forms based on the table.&nbsp;&nbsp;Default values at table level can be simple expressions, constants, etc, but there are no 'events' or 'triggers' in the table itself that would know when to apply this value if it's based on another field in the table.<br>--Jim&nbsp;&nbsp;
 
Yes, that code is for a control on a form, thanks Jim for adding that.<br><br>Thomas, maybe I should also mention that you would want to prevent users from being able to add or update items in the table through any other method than the form itself, or another form with the same code built in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top