473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Update Date Field (for Mod Date)

56 New Member
I would like to make my "MODDATE" field to be updated to the current date when user edit record by "Click on Save" button
Here is my code for the "Save" button:
Expand|Select|Wrap|Line Numbers
  1. Private sub Save Click()
  2. MsgBox "Record has been updated successfully!", vbInformation, "RECORD HAS BEEN UPDATED!"
  3.     Me.MODDATE.Value = Date
  4.     DoCmd.Close acForm, "frmReview", acSaveYes
  5. End Sub
  6.  
In the tblReview, I have a field call "MODDATE", and I set this field to have a default value =Now(). It works well when user enter new record, but not when user update existing record.
I also tried: me.MODDATE.Value=Now() and also me.MODDATE=Now(),
they all me error which completely stops my database application.

Can someone please help?
Thanks!
bluemoon
Feb 17 '09 #1
4 3592
Megalog
378 Recognized Expert Contributor
Interesting.. I use pretty much the same thing throughout my database, on the form's 'BeforeUpdate' event.

Expand|Select|Wrap|Line Numbers
  1. me.Modified.Value = format(Now(), "m/d/yyyy  h:mm:ss AM/PM")
In my table, the field is set as a Date/Time, with NO preset format or default value.
My only guess is that maybe you have a format set which is conflicting with what Now() is returning from your form? Or, your field is set as the wrong Data Type.. (text instead of Date/Time?)

Add some error handling to your save button event and see what it tells you.

-Edit: Just noticed this is in the wrong area, should be moved to the Answers section.
Feb 17 '09 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Bluemoon, You don't say in what way your code is failing. That would be useful.

The code there seems workable (assuming the MODDATE control is properly bound to the ModDate field in the underlying table).

PS. Use Date() for a simple date value, but Now() for a date value which includes the time element.
Feb 17 '09 #3
NeoPa
32,556 Recognized Expert Moderator MVP
Megalog, I recommend losing the Format() part of your code. This converts the date value to a string, which then only needs to be converted back automatically by Access. This won't fail, it is simply unnecessary (performance won't be noticeably different).

PS. Thanks for the heads-up about the wrong section. A better method for that would be the site's Report facility (top right of each post - other than your own). This will trigger an email to inform someone of the problem. Appreciate your help anyway.
Feb 17 '09 #4
missinglinq
3,532 Recognized Expert Specialist
A Couple of points:

First, of course, you don't really need a "Save" button in Access. Moving off of the record or closing the form will save the record.

Secondly

Close acForm, "frmReview", acSaveYes

isn't doing what you think! It's saving any changes made to the design of the form; it isn't saving the record.

And last, I wonder if NeoPa's statement

assuming the MODDATE control is properly bound to the ModDate field in the underlying table

has pinpointed the problem. You have a MODDATE field in your underlying table, but do you actually have a MODDATE control (textbox) on your form?

Linq ;0)>
Feb 18 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
3
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able...
4
by: news.btinternet.com | last post by:
I have a very simple database. I have information in a form that I would like to write to a table using some code. The table is called tblTest. The field I would like to write to is called Date....
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
22
by: tonialbrown | last post by:
I have an Sql update statement that I am using that updates the data from a record chosen by the user from a list box lstDelFrom. This is working for all the text fields & updates fine. Once I add...
4
by: dougmeece | last post by:
Morning Everyone... I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
5
by: Chris Cowles | last post by:
I use an application that uses Oracle 8.1.7. All functions of the application are completed with calls to stored procedures. A data entry error occurred that caused thousands of records to be...
4
by: Dr Al | last post by:
I have a project which requires the batch import of customer contact information, print mailing labels for those customers who have their date of first letter field in the database set to null, and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.