Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 21st, 2006, 12:07 PM
Authorized User
 
Join Date: Aug 2006
Location: Hoffman Estates, IL, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating a Date field based on another field

Hi everyone,
  I actually have two questions I need to ask and I'll break it up so it's easier to answer.

Question #1: I have a table where I have two date fields. "First_Session_Used" and "Scheduled_Review_Date" are the two fields. I need to create a query which will take the date in the "First_Session_Used" and increase that date by one year, but also change it so that it is the first date in that month. So, if the date in "First_Session_Used" is 6/7/06, the date would need to be 6/1/07 in "Scheduled_Review_Date". So, I need an update query which will help me accomplish this. Incidentally, the table is "Tbl_Book_Holding".

Question #2: Once I get my dates updated in the table using the query above, I need to modify the form so that the "Scheduled_Review_Date" is done in the same way as Question #1. So, suggestions on how to modify the form so that it inputs the information that way.

I appreciate any help anyone can give on this.

Thanks,
Arholly

Reply With Quote
  #2 (permalink)  
Old November 21st, 2006, 12:33 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hiya,

   For the Update Query (assuming a table name of Table1, and using DateStart as the first date field and DateEnd as the updated date field):

UPDATE Table1 SET Table1.DateEnd = DatePart("m",[DateStart]) & "/1/" & (DatePart("yyyy",[DateStart])+1);

Use the same formula on your form on the BEFORE INSERT and BEFORE UPDATE events.

Does this help?




mmcdonal
Reply With Quote
  #3 (permalink)  
Old November 21st, 2006, 01:13 PM
Authorized User
 
Join Date: Aug 2006
Location: Hoffman Estates, IL, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,
  Thanks for the query. Worked perfectly. I'm going to try the form now. Thanks again for your assistance.

Best Regards,
Arholly

Quote:
quote:Originally posted by mmcdonal
 Hiya,

†††For the Update Query (assuming a table name of Table1, and using DateStart as the first date field and DateEnd as the updated date field):

UPDATE Table1 SET Table1.DateEnd = DatePart("m",[DateStart]) & "/1/" & (DatePart("yyyy",[DateStart])+1);

Use the same formula on your form on the BEFORE INSERT and BEFORE UPDATE events.

Does this help?

mmcdonal
Reply With Quote
  #4 (permalink)  
Old November 21st, 2006, 01:29 PM
Authorized User
 
Join Date: Aug 2006
Location: Hoffman Estates, IL, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there again,
  I'm not getting this to work for the form. Am I missing something?

Best Regards,
Arholly

Quote:
quote:Originally posted by mmcdonal
 Hiya,

†††For the Update Query (assuming a table name of Table1, and using DateStart as the first date field and DateEnd as the updated date field):

UPDATE Table1 SET Table1.DateEnd = DatePart("m",[DateStart]) & "/1/" & (DatePart("yyyy",[DateStart])+1);

Use the same formula on your form on the BEFORE INSERT and BEFORE UPDATE events.

Does this help?




mmcdonal
Reply With Quote
  #5 (permalink)  
Old November 21st, 2006, 02:07 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, on the Before Insert event you would put:

Dim dtDateEnd As Date

dtDateEnd = DatePart("m",[DateStart]) & "/1/" & (DatePart("yyyy",[DateStart])+1)

Me.DateEnd = dtDateEnd

And the same on the Before Update event.

Did that work?



mmcdonal
Reply With Quote
  #6 (permalink)  
Old November 21st, 2006, 02:40 PM
Authorized User
 
Join Date: Aug 2006
Location: Hoffman Estates, IL, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Works like a charm. Thanks.

Quote:
quote:Originally posted by mmcdonal
 Sorry, on the Before Insert event you would put:

Dim dtDateEnd As Date

dtDateEnd = DatePart("m",[DateStart]) & "/1/" & (DatePart("yyyy",[DateStart])+1)

Me.DateEnd = dtDateEnd

And the same on the Before Update event.

Did that work?



mmcdonal
Reply With Quote
  #7 (permalink)  
Old November 22nd, 2006, 11:19 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

FYI: the technical term for this kind of coding is called "Regular Expression." There is an introduction to regular expressions scripting on Microsoft's MSDN site at: http://msdn.microsoft.com/library/de...63906a7353.asp



mmcdonal
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on updating the date field surya MySQL 2 September 17th, 2008 12:56 AM
Fill field based on another field skwilliams Classic ASP Basics 3 December 30th, 2006 11:02 AM
Inserting/updating with empty date field takabyte Classic ASP Databases 3 December 23rd, 2004 02:14 PM
Date Field from Parameter Field narooma.12 Crystal Reports 0 November 14th, 2004 08:51 PM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 11:30 PM



All times are GMT -4. The time now is 05:10 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.