How to use the button to update once n disable it until next month???

M

miles

hihi

i need some help . does the access allow the button to update once n
disable it until next month then the update button show again??


eg ----------
-update btn- when click the btn will be disable user from
clicking again.
----------

then after next month, the update btn show again for this month

this enable the user to click many times .

how do i make it???

thanks
 
N

Nikos Yannacopoulos

Miles,

Use a table to record update dates (all you need is one Date/Time
field). Then add a few of lines of code at the end of the button's Click
procedure to (a) add a record with the current date and time to the
table, and (b) disable the button. Additionally, add a few lines of code
to the form's Open event to check the month part of the last recorded
update date against the month part of the current date, and enable or
disable the button accordingly.

Example code addition to the button Click sub:

Private Sub YourButtonName_Click()
Dim strSQL As String
'your existing code
'....
strSQL = "INSERT INTO tblUpdateLog ( UpdateDate )" & _
"SELECT " & Now()
CurrentDb.Execute strSQL, dbFailOnError
Me.YourButtonName.Enabled = False
End Sub

where I have assumed the table name to be tblUpdateLog, with a field
named UpdateDate. Replace YourButtonName with the actuall name of the
command button.

Example code for the form's Open event:

Private Sub Form_Open(Cancel As Integer)
Dim dtLast As Date
dtLast = DMax("[UpdateDate]", "tblUpdateLog")
If dtLast < Now() And Month(dtLast) <> Month(Now()) Then
Me.YourButtonName.Enabled = True
Else
Me.YourButtonName.Enabled = False
End If
End Sub

Again, same naming assumptions.

HTH,
Nikos
 
Top