Updating A Date Field Via A Button (1 Viewer)

03erringtonl

New member
Local time
Today, 17:18
Joined
Feb 19, 2014
Messages
6
Hi,

I'm having a problem trying to update a date field from a button.

I have a form called Add_New_Domain which runs from a table called Domain_Names.

Within the form there is a field called Expiry_Date which tells me when the domain is set to expire. When I first create an entry I manually enter a date in here.

However, every year when the domain renews I would like to increase this date by exactly a year by clicking a button which is also on the form.

Can anyone help me with the code which I need to make this happen as I have tried everything that I can see on the internet already and nothing seems to work.

Thanks is advance
 

namliam

The Mailman - AWF VIP
Local time
Today, 18:18
Joined
Aug 11, 2003
Messages
11,695
I personally wouldnt over write any existing data, because once lost it isnt recovarable...
You might administrate your lost data in a subtable or even administrate your expiry dates in a seperate table....

However to answer your question
Me.Expiry_Date = Dateadd("YYYY",1,Me.Expiry_Date)

Should do what you are discribing...
 

03erringtonl

New member
Local time
Today, 17:18
Joined
Feb 19, 2014
Messages
6
Thanks for your quick reply... I have tried the code that you send and I am now presented with the following error message when I click the button



Microsoft Access cannot find the object 'Me.'

If 'Me' is a new macro or macro group, make sure you have saved it and that you have typed its name correctly.


Does that mean anything to you?
 

namliam

The Mailman - AWF VIP
Local time
Today, 18:18
Joined
Aug 11, 2003
Messages
11,695
Me should be a reference to the form you are in? are you not using the code inside the form?
 

03erringtonl

New member
Local time
Today, 17:18
Joined
Feb 19, 2014
Messages
6
Yes... I'm using the code inside the form. I am right in thinking that the code should be applied to the on click event on the button?
 

Mile-O

Back once again...
Local time
Today, 17:18
Joined
Dec 10, 2002
Messages
11,316
From memory, should it not be this?
Code:
Me.[Expiry_Date] = DateAdd("yyyy", 1, Me.[Expiry_Date]

If you're going to put horrible characters in your names, you're going to have to remember to add square brackets every time.
 

03erringtonl

New member
Local time
Today, 17:18
Joined
Feb 19, 2014
Messages
6
Hi,

Thanks for your reply.

I am still getting the same response when I use the square brackets.
 

namliam

The Mailman - AWF VIP
Local time
Today, 18:18
Joined
Aug 11, 2003
Messages
11,695
I dont know what you are doing wrong, I just tested it to make sure on an empty form I made a control txtTest
Made a button btnTest
added this code to the button:
Code:
Private Sub btnTest_Click()
If IsNull(Me.txtTest) Then Me.txtTest = Date
Me.txtTest = DateAdd("YYYY", 1, Me.txtTest)
End Sub

It works like a charm, you will need to post your DB with the form and control and code to see whats going on and what you are doing wrong... cause it should just work.
 

03erringtonl

New member
Local time
Today, 17:18
Joined
Feb 19, 2014
Messages
6
Thanks for your continued efforts... I really appreciate it.

Database is attached... The form in question is Add New Domain.
 

Attachments

  • Multimedia Service Record.zip
    107.2 KB · Views: 82

03erringtonl

New member
Local time
Today, 17:18
Joined
Feb 19, 2014
Messages
6
Can you upload the files I sent you with the added code in.

I am either seriously getting this wrong as its still not working when I put the code in or there is something messing up with my computer/access.

Thanks
 

namliam

The Mailman - AWF VIP
Local time
Today, 18:18
Joined
Aug 11, 2003
Messages
11,695
I already gave you the exact code.... Just go into design mode of the form,
right click the button,
choose "build event..."
Choose "code builder"
The private sub and end sub lines are already there, paste the one line of code there and your golden :/
 

Users who are viewing this thread

Top Bottom