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!

Applying Default Value to Bound TextBox 1

Status
Not open for further replies.

BStatnick

MIS
Nov 30, 2004
8
US
Greetings,

I have a form that allows the user to update a date field by entering a value into a textbox that is bound to a field in a Table. The query that generates the recordset for the form looks for a null value in the field when it selects the rows. The users would like the current date to appear in the textbox when the form is opened to allow for faster processing. I currently have the textbox formatted to the short date format and have a "_ _/_ _/_ _" mask applied. The form was developed in Access 97. Is there any way to apply a default to this control without extensive coding? Thanks in advance for your assistance with this request!!

Sincerely,
BStatnick
 
set the default value of the textbox to what ever you want!

rightclick the control(textbox) in form design view and find the default value property.
 
For existing records, this could be a little confusing to the user. Because, if you set the field's value to the current date, the record has now been modified and will be saved when the user leaves the record unless the user cancels the change. Chances are, if they are just crusing thru the records, they are not going to think to cancel the change everytime they go to a new record. (And it's going to be a little difficult to handle it if the form is shown in datasheet view.)

I would suggest placing a button or something next to the date field. When the user clicks the button, it places the current date in the field.

Or you could, in the BeforeUpdate event of the form, set the field's value to the current date.

You could set the default value property of the field within the table to Date (or Now, depending on if you wanted to include the time). Now everytime the user goes to a NEW record, the current date will already be in the field.

Default Value ... Date()
 
I would suggest placing a button or something next to the date field. When the user clicks the button, it places the current date in the field.

Or you could, in the BeforeUpdate event of the form, set the field's value to the current date.

Or, use the BeforeUpdate to ask the person if they wish to save the changes.

Stewart J. McAbney | Talk History
 
Thank you to everyone for your quick responses! I opted for the button on the form to fill the textbox. I tried to set the default property, but I believe that there is an issue with the control source for the textbox being set to the field in the table that may be overriding the control default property. In any case, the use of the button will be the best solution, especially since there is a limited amount of resources that I can spend on this particular project.
If I should come across anything that expands on this issue, I'll post it here for future reference. Thanks again!

BStatnick
 
If you want to set the value to a date (remember that the record will then be marked as changed), here's how you do it. Note that on current records, the DefaultValue property will not update the field. Therefore, in the OnCurrent event of the form, set its value. Set the default value property via the OnOpen event of the form.

Private Sub Form_Current()

If (IsNull(txtYourControl)) Then txtYourControl.Value = Date

End Sub

Private Sub Form_Open(Cancel As Integer)

txtYourControl.DefaultValue = """" & Date & """"

End Sub
 
Many thanks and a star for FancyPrairie! The OnCurrent event provides the best solution for my needs. Best wishes and much success to everyone.

Bob
 
Just a quick final note...

When using the OnCurrent event of the form, I discovered that I had to set the Form's Cycle property to Current Record, otherwise I would update records simply by accessing the form. Once the cycle property is set, no problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top