Extend date after checkbox ticked

  • Thread starter Thread starter Caroline Higson
  • Start date Start date
C

Caroline Higson

Hi

I have a table of sponsorships with name, address, and date of expiry
in Access 03. After the year is up I want the user to be table to tick
a checkbox (that I added onto the table) and this will extend the date
by one year.

Can't seem to find an afterupdate function for checkboxes and no idea
if an update query would work, or even what one is!

Any ideas on what would be best?

Thanks
Caroline
 
Caroline:

You don't need to include a field in the table or have a check box on the
form. On a form bound to the table add a suitably captioned command button
and put this in its Click event procedure:

Me.[ExpiryDate] = DateAdd("yyyy",1, Me.[ExpiryDate])

where ExpiryDate is the name of the field in question. This will update the
current record's ExpiryDate by one year. The record will be saved when you
move to another record, close the form etc., but if you wanted it saved
immediately with the new date just add another line of code:

RunCommand acCmdSaveRecord

I f you wanted the button only to be available if the old date has been
reached put the following code in the form's Current event procedure:

Me.cmdUpdateExpiryDate.Enabled = (Me.[ExpiryDate] <= VBA.Date)

where cmdUpdateExpiryDate is the name of the button. And add the following
extra lines of code to the button's Click event procedure:

Me.[ExpiryDate].SetFocus
Me. cmdUpdateExpiryDate.Enabled = False

You have to move focus away from the button before you can disable it, so
setting focus to the ExpiryDate control will do this. You can move it to any
control other than the button, however, if you wish.

Ken Sheridan
Stafford, England
 
exactly what I needed-thank you!

Ken said:
Caroline:

You don't need to include a field in the table or have a check box on the
form. On a form bound to the table add a suitably captioned command button
and put this in its Click event procedure:

Me.[ExpiryDate] = DateAdd("yyyy",1, Me.[ExpiryDate])

where ExpiryDate is the name of the field in question. This will update the
current record's ExpiryDate by one year. The record will be saved when you
move to another record, close the form etc., but if you wanted it saved
immediately with the new date just add another line of code:

RunCommand acCmdSaveRecord

I f you wanted the button only to be available if the old date has been
reached put the following code in the form's Current event procedure:

Me.cmdUpdateExpiryDate.Enabled = (Me.[ExpiryDate] <= VBA.Date)

where cmdUpdateExpiryDate is the name of the button. And add the following
extra lines of code to the button's Click event procedure:

Me.[ExpiryDate].SetFocus
Me. cmdUpdateExpiryDate.Enabled = False

You have to move focus away from the button before you can disable it, so
setting focus to the ExpiryDate control will do this. You can move it to any
control other than the button, however, if you wish.

Ken Sheridan
Stafford, England

Caroline Higson said:
Hi

I have a table of sponsorships with name, address, and date of expiry
in Access 03. After the year is up I want the user to be table to tick
a checkbox (that I added onto the table) and this will extend the date
by one year.

Can't seem to find an afterupdate function for checkboxes and no idea
if an update query would work, or even what one is!

Any ideas on what would be best?

Thanks
Caroline
 

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

Similar Threads


Back
Top