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

Date

Status
Not open for further replies.
Sep 21, 2001
28
US
I have a button and a textbox controls on a form. My question pertains to how do I program to make the textbox displays the current date whenever the button control is pressed. The textbox is a reference user used to determine the last update. I want the date to stay static until the button is pressed again. I do not have any sample codes available, but my problem occurs whenever I exit Access, the date in the textbox disappears.
 
store the date to a table, then when you open the form, open the table and get the value, then when you click on the command button, reset the textbox and also the value in the table

For ACCESS 97

Option Compare Database
Option Explicit
Dim db As DAO.database, rst As DAO.Recordset

Private Sub cmdSetDate_Click()
TextBoxWithDate = Date
Set db = CurrentDb
Set rst = db.OpenRecordset("TableWithValue")
With rst
If .RecordCount > 0 Then
.MoveFirst
.Edit
Else
.AddNew
End If
rst!DateField = TextBoxWithDate
.UPDATE
End With
Set db = Nothing
Set rst = Nothing
End Sub

Private Sub Form_Load()
Set db = CurrentDb
Set rst = db.OpenRecordset("TableWithValue")
With rst
If .RecordCount > 0 Then
.MoveFirst
TextBoxWithDate = rst!DateField
End If
End With
Set db = Nothing
Set rst = Nothing
End Sub

PaulF
 
This works like a charm. Thank you for the prompt reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top