Disable a command button every day except on last date of month

A

Azad, DH, BD

Dear all Geniouses,

I'm highly requesting u all to give me ur wise solution to my problem bellow:
I've a table where whole month datas are appended by an append query on the
last date of that month. By clicking a command button the append query runs &
appends data to the table. But if the command button is clicked once more the
data will be repeatative. So I want the command button to be active only on
the last date of the month and after appending the data to table the button
will remain inactive untill the next month last date. how can I do this? pls
give me the sample code or to the point advice.

Waiting eagerly for ur solution.
Thanx u all in advance
 
M

Michael Gramelspacher

Dear all Geniouses,

I'm highly requesting u all to give me ur wise solution to my problem bellow:
I've a table where whole month datas are appended by an append query on the
last date of that month. By clicking a command button the append query runs &
appends data to the table. But if the command button is clicked once more the
data will be repeatative. So I want the command button to be active only on
the last date of the month and after appending the data to table the button
will remain inactive untill the next month last date. how can I do this? pls
give me the sample code or to the point advice.

Waiting eagerly for ur solution.
Thanx u all in advance

You have a serious design problem, if you can add duplicate records every time you click the button.
The table should reject any records which are duplicates. Even if your table will not do this, you
can do a lookup to check whether the records are already there, before trying to add them again.

Me.Somebutton.enabled = (date()=Dateadd("m",Datediff("m",1,date()),1))

Note though that the last day of this month will be a Sunday. Will you be around on Sunday to press
the button.

Another approach would be to have a table with the dates the button is to be active. Then do this:

Private Sub Form_Open(Cancel As Integer)
Me.somebutton.Enabled = DCount("*", "[EOM Calendar]", "[calendar_date] = #" & Date & "#") > 0
End Sub

It seems that you are deliberately mangling the English Language; it is definitely not cool.
 
M

MikeB

Michael Gramelspacher said:
You have a serious design problem, if you can add duplicate records every
time you click the button.
The table should reject any records which are duplicates. Even if your table
will not do this, you
can do a lookup to check whether the records are already there, before trying
to add them again.

Me.Somebutton.enabled = (date()=Dateadd("m",Datediff("m",1,date()),1))

Note though that the last day of this month will be a Sunday. Will you be
around on Sunday to press
the button.

further that won't prevent the button from being pressed multiple times on
the last day of the month.
Another approach would be to have a table with the dates the button is to be
active. Then do this:

Private Sub Form_Open(Cancel As Integer)
Me.somebutton.Enabled = DCount("*", "[EOM Calendar]", "[calendar_date] = #" &
Date & "#") > 0
End Sub

It seems that you are deliberately mangling the English Language; it is
definitely not cool.
 
M

Michael Gramelspacher

further that won't prevent the button from being pressed multiple times on
the last day of the month.

Certainly true. Possibly add another column to the EOM Calendar to show whether the add has been
done. So, the Dcount would have to consider two conditions. The code that runs the insert query
would also have to update the EOM Calendar column. I would not have a table that permitted
duplicates. Then the second insert would not work, and the error could be trapped and ignored.

Maybe someone else has other suggestions for the poster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top