473,412 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Date Modified for information in a Subform

Hello all!

I have a customer relationship management database that I am having a small problem with. I have built a dashboard for the employees to use, and the dashboard contains a subform. The subform is a query of any projects marked as Priority "1" and it contains about 20 records. I have added a DateModified field to the table that is used by multiple forms to record the most recent date that record was changed.

My problem now is to figure out how to update that field when record changes are made in the subform on the dashboard. So if one of the users edits the information for one of the projects in the subform, it will change the DateModified field basically. Any ideas?

Thanks in advance for your help!
Oct 22 '12 #1
8 4231
TheSmileyCoder
2,322 Expert Mod 2GB
Well presumably you have a foreign key linking the items in the subform to the main item. Using the AfterUpdate event of the subform, you could run a update query:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.   Currentdb.Execute "UPDATE tbl_Main SET DateModified=Now() WHERE PrimaryKeyName=" & Me.ForeignKey
  3. End Sub
Im not 100% sure on the SQL syntax, its really not my strong suit, but the example should still outline the general principle. Whether you want to use Now() or Date() depends on your needs. I prefer to use NOW() but often just format the information to only display the date. That way I have the accurate information in the table while storing as much detail as possible.
Oct 22 '12 #2
Thank you for your quick reply! I will make the changes this afternoon and see if they work. I can give you feedback tomorrow. Thanks again!
Oct 22 '12 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Your welcome.
Oct 22 '12 #4
NeoPa
32,556 Expert Mod 16PB
First, it's very important to decide whether your date field is a date field or a timestamp field. My advice differs here from Smiley's as I believe it's always important to know the difference and treat them differently. So many people get confused about this and fail to get their projects working properly when they try to treat dates as timestamps and vice-versa. If I'm working with simple date values and want to ignore anything after today I can simply say X <= Date(). If X turns out to be a timestamp value though, this will ignore anything from today too (as a timestamp from today (except on the stroke of midnight) is numerically greater than the date value on its own).

I'll continue on the assumption that you're working with dates specifically, as indicated by the question.
Typically, a suggestion just as Smiley has given would be recommended at this point. However, there is a way that allows the updates to be atomic, and therefore less exposed to partial updates. Let me outline that for you.

When you are processing the save you check the date value of the record. If it is not set to today then you need to do three things in succession.
  1. Cancel the current update.
  2. Set the date value to Date().
  3. Resubmit the update.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     With Me
  3.         If Format(Nz(.DateField, ""), "yyyymmdd") = _
  4.            Format(Date(), "yyyymmdd") Then Exit Sub
  5.         Cancel = True
  6.         .DateField = Date()
  7.         Call DoCmd.RunCommand(acCmdSaveRecord)
  8.     End With
  9. End Sub
This way only a single (atomic) update is done, which includes all required changes together.
Oct 24 '12 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Hi NeoPa. You have some good points about querying the date.

I wonder however, if you missed the part about the datefield being updated belongs to the main (parent) form and not the subform which is being updated?

Furthermore should you require the setting of fields in a forms beforeupdate event, you do not need to cancel the update first.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   Me.txt_DateChanged=Now()
  3.   Me.txt_ChangedByID=UserID()
  4. End Sub
Is a code I use many forms, without first cancelling the update. I would be interested in knowing if you have any cases in which a cancel of the update is required before resubmitting it?
I know if you want to UNDO a entry while in the forms beforeUpdate event, it is necessary to cancel it first.
Oct 24 '12 #6
NeoPa
32,556 Expert Mod 16PB
Smiley:
I wonder however, if you missed the part about the datefield being updated belongs to the main (parent) form and not the subform which is being updated?
Very likely. Especially as I don't see that even now when I look. To be fair, the explanation isn't too clear and I could be wrong, but I still interpret the question to refer to changes within the same record (which makes sense if you think about it). On the other hand, if that's not a correct interpretation, which frankly is quite possible, then my suggestion wouldn't be appropriate.

Smiley:
Furthermore should you require the setting of fields in a forms beforeupdate event, you do not need to cancel the update first.
You're probably correct I expect. I'd recently tried something along similar lines and found I had to, but when I tried to dig it up to check the details (for the post) I couldn't remember which database it was even in :-(
Oct 24 '12 #7
Sorry for the confusion, I will clarify some things. The field being used on the main table is a Date/Time field, using mm/dd/yyyy format. The subform on the dashboard is a query that pulls up all of the records that have been marked as a priority 1 so the user can have a quick list of all of the important ones. The user will then proceed to provide updates to individual records within the subform. Not all records will be updated. What I want to do is have the DateModified field for each individual record change to the current date once that record has been updated. Again, sorry for the confusion
Oct 26 '12 #8
TheSmileyCoder
2,322 Expert Mod 2GB
If the date field is part of the recordsource for the subform, then add code to the subforms BeforeUpdate event as shown in #6, otherwise the approach from #2.


Remember that a dataField stores a date (And possibly a time as well). The format is merely how it is displayed. Consider that the information is stored the same way whether you are in the US or in europe, but in place its formatted mm/dd/yyyy and in another its dd/mm/yyyy. The storing is independent of the format AS LONG as you use the date time field, and not a text field.
Oct 26 '12 #9

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

Similar topics

3
by: Eclectic | last post by:
I have a script that reads all directory names within a specific location (only containing folders), then lists all jpeg files in those directories. Here is my script: function...
3
by: Lee Holsenbeck | last post by:
i have been using the getfiles method, but that retrieves only alphabetically. i'd like to be able to retrieve filenames in a directory by thier date modified. does .net have a method for this ?...
1
by: Sebastian Santacroce | last post by:
Hi, How do I get the Date Modified from a file that was selected with the OpenFileDialog? Thanks,
3
by: Cornjerker | last post by:
I see where I can change the date a file is created.... File.SetCreationTime(path) But how can I change the date a file is modified. Thanks, C
2
by: wsnyder3 | last post by:
I have many forms but all the information is related to one another. I wanted to know if there was a way that if someone updates a account that it will show the last date modified on all the...
2
by: asma410 | last post by:
Is it possible to display the file created & file modified information on a switchboard? I have designed the database so that when the user clicks on an icon on the switchboard, a form (linked to a...
28
Ericks
by: Ericks | last post by:
I want to highlight new data that has been entered in my database since a last meeting so it is easy to see in a subform’s table what info is new. In my database I have a table called...
1
by: pjnambiar | last post by:
Hello friends can any one help me out by providing code to read the date modified of a file. this is required because I have developed a enquiry utility where in i have to update the database...
2
by: ragazzo | last post by:
I am using this code to load files But i have problem when there is a large number of files, ( it shows nothing ) is it posible to list only files where date modified is today`s date. And show in...
0
by: carmeno | last post by:
Hi can someone please help me. i have an assignment due and i need to use DOS on windows xp and-take a screen capture of ( i can do a screen capture its the following that is the problem) directory...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.