Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-19-2014, 08:05 AM   #1
03erringtonl
Newly Registered User
 
Join Date: Feb 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03erringtonl is on a distinguished road
Updating A Date Field Via A Button

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

03erringtonl is offline   Reply With Quote
Old 02-19-2014, 08:09 AM   #2
namliam
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 11,388
Thanks: 0
Thanked 800 Times in 787 Posts
namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light
Re: Updating A Date Field Via A Button

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...
__________________
ruoY yppah namliaM si syawla yppah ot pleh
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Remember to use the scales (Bottom left) or the thumb (bottom right)

Always looking for new challenges (Amsterdam Area)
namliam is offline   Reply With Quote
Old 02-19-2014, 08:41 AM   #3
03erringtonl
Newly Registered User
 
Join Date: Feb 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03erringtonl is on a distinguished road
Re: Updating A Date Field Via A Button

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?

03erringtonl is offline   Reply With Quote
Old 02-19-2014, 09:33 AM   #4
namliam
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 11,388
Thanks: 0
Thanked 800 Times in 787 Posts
namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light
Re: Updating A Date Field Via A Button

Me should be a reference to the form you are in? are you not using the code inside the form?
__________________
ruoY yppah namliaM si syawla yppah ot pleh
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Remember to use the scales (Bottom left) or the thumb (bottom right)

Always looking for new challenges (Amsterdam Area)
namliam is offline   Reply With Quote
Old 02-19-2014, 09:40 AM   #5
03erringtonl
Newly Registered User
 
Join Date: Feb 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03erringtonl is on a distinguished road
Re: Updating A Date Field Via A Button

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?
03erringtonl is offline   Reply With Quote
Old 02-19-2014, 09:58 AM   #6
Mile-O
Back once again...
 
Mile-O's Avatar
 
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 11,312
Thanks: 4
Thanked 118 Times in 108 Posts
Mile-O will become famous soon enough
Re: Updating A Date Field Via A Button

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.
Mile-O is offline   Reply With Quote
Old 02-20-2014, 01:47 AM   #7
03erringtonl
Newly Registered User
 
Join Date: Feb 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03erringtonl is on a distinguished road
Re: Updating A Date Field Via A Button

Hi,

Thanks for your reply.

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

03erringtonl is offline   Reply With Quote
Old 02-20-2014, 02:11 AM   #8
namliam
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 11,388
Thanks: 0
Thanked 800 Times in 787 Posts
namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light
Re: Updating A Date Field Via A Button

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.
__________________
ruoY yppah namliaM si syawla yppah ot pleh
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Remember to use the scales (Bottom left) or the thumb (bottom right)

Always looking for new challenges (Amsterdam Area)
namliam is offline   Reply With Quote
Old 02-20-2014, 02:17 AM   #9
03erringtonl
Newly Registered User
 
Join Date: Feb 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03erringtonl is on a distinguished road
Re: Updating A Date Field Via A Button

Thanks for your continued efforts... I really appreciate it.

Database is attached... The form in question is Add New Domain.
Attached Files
File Type: zip Multimedia Service Record.zip (107.2 KB, 55 views)
03erringtonl is offline   Reply With Quote
Old 02-20-2014, 02:48 AM   #10
namliam
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 11,388
Thanks: 0
Thanked 800 Times in 787 Posts
namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light
Re: Updating A Date Field Via A Button

Cant see what you did or didnt try, since your database doesnt contain ANY VBA at all...
However,
Code:
Private Sub Command33_Click()
Me.Expiry_Date = DateAdd("YYYY", 1, Me.Expiry_Date)
End Sub
Worked just perfectly.

Please do have a read here: http://www.access-programmers.co.uk/...on#post1152269
__________________
ruoY yppah namliaM si syawla yppah ot pleh
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Remember to use the scales (Bottom left) or the thumb (bottom right)

Always looking for new challenges (Amsterdam Area)
namliam is offline   Reply With Quote
Old 02-20-2014, 04:01 AM   #11
03erringtonl
Newly Registered User
 
Join Date: Feb 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03erringtonl is on a distinguished road
Re: Updating A Date Field Via A Button

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
03erringtonl is offline   Reply With Quote
Old 02-20-2014, 11:23 PM   #12
namliam
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 11,388
Thanks: 0
Thanked 800 Times in 787 Posts
namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light namliam is a glorious beacon of light
Re: Updating A Date Field Via A Button

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 :/

__________________
ruoY yppah namliaM si syawla yppah ot pleh
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Remember to use the scales (Bottom left) or the thumb (bottom right)

Always looking for new challenges (Amsterdam Area)
namliam is offline   Reply With Quote
Reply

Tags
button , date field , dateadd , form

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a Date Field in Access with SQL BE jcruzAME Queries 1 11-18-2011 05:17 AM
trouble with updating date field Gregvg Modules & VBA 2 01-04-2010 12:32 PM
Updating a field using combo boxes and command button pam0566 Forms 2 06-12-2008 08:56 AM
Updating Field by Command Button jamjarr Forms 3 11-05-2006 04:24 AM
[SOLVED] Updating a field to current date sunny Forms 2 02-19-2005 08:54 AM




All times are GMT -8. The time now is 07:47 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World