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

Setting a date to textbox

Status
Not open for further replies.

macleodjb

Technical User
Aug 27, 2007
10
I am new to coding with vba in access. I have a checkbox and a textbox. I want to be able to check the checkbox and it sets todays date in the textbox. How can i do this? Thanks in advance.
 




Hi,
Code:
me.textbox1.text = format(date, "yyyy/mm/dd")


Skip,

[glasses] When a wee mystic is on the loose..
It's a Small Medium at Large! [tongue]
 
You'd have to set focus on textbox1 before using textbox1.text, Skip!

Code:
Private Sub YourCheckBox_Click()
 If YourCheckBox Then
  Me.textbox1.Value = Format(Date, "yyyy/mm/dd")
 End If
End Sub

And actually, since .Value is the default property for a textbox, you could simply use

Me.textbox1 = Format(Date, "yyyy/mm/dd")

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
I am going to have more than one checkbox and textbox that will set the date in the same form. Is there a way to get element id or something. Like javascript you can get the element id for the checkbox so you only have one Private Sub to enter the date for the pertaining textbox. Can we do the same here? If so how. Thanks in advance.
 
I'm a little confused. Are you talking about using a sub to set the Date for each textbox? What's the point? You'd still have to call the sub from each object, and you're talking about one line of code to simply set the date. If your object is just to have the date set for a textbox, why not use the double-click event for each checkbox? You wouldn't even have to change the code for each field, just use this:
Code:
Private Sub YourTextBoxName_DblClick(Cancel As Integer)
 Me.ActiveControl = Date
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top