473,397 Members | 1,972 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,397 software developers and data experts.

Automatic date Insertion

lee123
556 512MB
Hello its been awhile since i have been on this page but was wondering if someone could help me figure out this problem?

I have a field on my form named "Tdate" actually it's in a subform on a form and right now i have to enter in a certain date and the subform is set to continuous form. so my question is....how can i enter in a date and when i have entered in all the fields for that record have the next date automatically enter in the next record. for instance if i was to enter in a date such as 10/01/09 then the next record in the "Tdate" field would be 10/02/09 and so on.

Can this be done? or is there another way to do this...

lee123
Oct 16 '09 #1

✓ answered by NeoPa

I did some testing and (with the help of MSquared) found that the Form_AfterUpdate event was not the best one to use as it would set the .DefaultValue wrongly when any previous records were edited. Instead I would use Form_AfterInsert.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2.     With Me.TDate
  3.         .DefaultValue = Format(.Value + 1, "\#m/d/yyyy\#")
  4.     End With
  5. End Sub
Try this and let us know how you get on.

30 2424
NeoPa
32,556 Expert Mod 16PB
In the AfterUpdate event procedure for TDate, set the .Default property to TDate + 1.
Oct 16 '09 #2
lee123
556 512MB
So i put it like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub tDate_AfterUpdate()
  2.     tDate.DefaultValue = tDate + 1
  3. End Sub
lee123
Oct 16 '09 #3
NeoPa
32,556 Expert Mod 16PB
You've got the idea, but it's not the .DefaultValue property.
Oct 17 '09 #4
lee123
556 512MB
ok i don't understand what you mean by default property because there is only the "DefaultValue" there unless im not understanding what your talking about.

lee123
Oct 17 '09 #5
NeoPa
32,556 Expert Mod 16PB
OK. Let me check this out for you here. Tell me, what version of Access are you using, and what type of control is tDate?
Oct 17 '09 #6
lee123
556 512MB
Ok the version of "Access is 2000 Premium / Developers Tools 1.5" and the control is a "Textbox" Sorry for the incomplete info i should of said in my first post what version i was using
Oct 17 '09 #7
NeoPa
32,556 Expert Mod 16PB
I'm sorry Lee. I was sure I had it right, but it seems DefaultValue it is, and DefaultValue it always was. I do apologise for wasting your time.
Oct 18 '09 #8
lee123
556 512MB
so there is no way to do this? or someone else might know how.

lee123
Oct 18 '09 #9
NeoPa
32,556 Expert Mod 16PB
No. What I'm saying is that you suggestion was perfectly correct. I was in error to try to correct you.

That code should work for you. If it doesn't then please post the details so I can think about it further. I have no reason to expect it not to though.
Oct 18 '09 #10
lee123
556 512MB
well the code works but it leaves a time instead of the date.

lee123
Oct 18 '09 #11
NeoPa
32,556 Expert Mod 16PB
Dates & times are generally stored together, so I expect it is simply showing (formatted) as a time (but is a Date/Time in disguise). Having said that, I expect you really want a pure date for something like this. It looks like you need to find out why [tDate] has a date with an associated time in the first place ;)
Oct 18 '09 #12
lee123
556 512MB
gee i never new how difficult this is turning out to be thanks anyway

lee123
Oct 18 '09 #13
NeoPa
32,556 Expert Mod 16PB
Can you say how [tDate] gets its original value(s)? I expect the problem is tied up with that somehow. Be careful of the formatting too. That can be particularly confusing when dealing with Date/Times.
Oct 18 '09 #14
lee123
556 512MB
well to sum it up i enter in the date manually as i said in my first post

I have a field on my form named "Tdate" actually it's in a subform on a form and right now i have to enter in a certain date and the subform is set to continuous form
but i just wanted it to enter in itself when i move to the next record. And in the table it is set to "Date/time" in the "Date Type"

lee123
Oct 18 '09 #15
NeoPa
32,556 Expert Mod 16PB
OK Lee. Can you do two things for me.
  1. Get (& post) the Format property of the [tDate] control of your form.
  2. Add a line after line #2 of the code in your post #3 :
    Expand|Select|Wrap|Line Numbers
    1. Call MsgBox(Me.tDate, "dd/mm/yyyy hh:nn:ss")
    When the message box pops up make a note of it and post it in here.
I'll see if I can work out what is causing the strange behaviour.
Oct 18 '09 #16
lee123
556 512MB
Ok the Format Property is set to "Short Date" and the Error it keeps bringing up (not the msgbox) is a "Runtime Error 13 Type Mismatch" and it is pointing to this code.

Expand|Select|Wrap|Line Numbers
  1. Call MsgBox(Me.tDate, "dd/mm/yyyy hh:nn:ss") 
as you asked i have put the code like this now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TDate_AfterUpdate()
  2.     TDate.DefaultValue = TDate + 1
  3.     Call MsgBox(Me!TDate, "dd/mm/yyyy hh:nn:ss")
  4. End Sub
is this the information you wanted or did i misunderstood your directions...

lee123
Oct 19 '09 #17
NeoPa
32,556 Expert Mod 16PB
It seems this thread is where I come to make all my mistakes Lee. I'm so sorry.
Expand|Select|Wrap|Line Numbers
  1. Call MsgBox(Me!TDate, "dd/mm/yyyy hh:nn:ss")
should be :
Expand|Select|Wrap|Line Numbers
  1. Call MsgBox(Format(Me.TDate, "d mmm yyyy HH:nn:ss"))
I'd left out the Format function entirely. I generally try not to be that careless.

Also, as you're from the USA I thought I'd format it in a way more recognisable for you too.
Oct 19 '09 #18
lee123
556 512MB
ok it works and the msgbox comes up i have entered in the tdate "01/15/09" and the msgbox reads "15 Jan 2009 00:00:00"

the code i have entered in now is..

Expand|Select|Wrap|Line Numbers
  1. Private Sub TDate_AfterUpdate()
  2.     TDate.DefaultValue = TDate + 1
  3.     Call MsgBox(Format(Me.TDate, "d mmm yyyy HH:nn:ss"))
  4. End Sub
so now what do i do..

lee123
Oct 20 '09 #19
NeoPa
32,556 Expert Mod 16PB
Frankly, I'm struggling to see where post #11 is coming from. This seems to be working exactly as I'd intended. Try the following and we will see if anything shows there :
Expand|Select|Wrap|Line Numbers
  1. Private Sub TDate_AfterUpdate()
  2.     With Me.TDate
  3.         .DefaultValue = .Value + 1
  4.         Call MsgBox(Format(.Value, "d mmm yyyy HH:nn:ss") & vbCrLf & _
  5.                     Format(.DefaultValue, "d mmm yyyy HH:nn:ss"))
  6.     End With
  7. End Sub
Oct 20 '09 #20
lee123
556 512MB
Well Neopa,

This works fine the msgbox pops up with the two dates so when i enter in a date it shows the date (I entered) and the next date this is what i want it to do.

lee123
Oct 21 '09 #21
NeoPa
32,556 Expert Mod 16PB
That's good to hear Lee, although I'm not sure you quite have the hang of this new feature. The idea I think is to click on the post in the thread that, in your opinion, most closely answers your question.

This is then showed (repeated) at the top of the thread, near the Original Post, so anyone searching can find the answer easily and simply.
Oct 21 '09 #22
lee123
556 512MB
i don't get what is going on or the hang of this. i still havent found a way to get the next date into the tdate field after i have entered in a date. i didn't want it to pop up in a msgbox, i wanted to know how i could enter in a date in the tdate field and then instead of me entering in the next date have it already there. so i could just enter in the other fields i have on my form.

so when i answered this:

This works fine the msgbox pops up with the two dates so when i enter in a date it shows the date (I entered) and the next date this is what i want it to do
.
thats it.. i guess i shouldn't of answered the way i did on that post, i was just telling you that the way you did the code worked fine and thats the way i wanted it to be entered in the tdate textbox (Not in a msgbox) when i entered in a date in the tdate field..things have changed on this fourm.

lee123
Oct 22 '09 #23
NeoPa
32,556 Expert Mod 16PB
I have to say I cannot see why this is not working for you. The MsgBox code was to tell us that the control contains valid data first of all, and that the next entry will also default to the value you require. As far as I can see the results confirm this, yet you tell me this is not happening :S I can only guess that there is something else quite important that hasn't been posted yet. As this is likely to be hard to find via this interface (Hands-up those who are not here), I suggest it may be time to post a copy of your database. I'll include some instructions below.

When attaching your work please follow the following steps first :
  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
  3. If you've done anything in steps 1 or 2 then make sure that the problem you're experiencing is still evident in the updated version.
  4. Compact the database.
  5. Compress the database into a ZIP file.
  6. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
It would also be helpful, as we now understand that the issue is not resolved, to post exactly what was contained in the MsgBox.
Oct 22 '09 #24
lee123
556 512MB
hello Neopa, here is the database for you can look at it and as i said in post #21

This works fine the msgbox pops up with the two dates so when i enter in a date it shows the date (I entered) and the next date this is what i want it to do.
the msgbox works but i do understand how i can get it to be in the Tdate textbox.

take a look at the database it is a access 2000 version

lee123
Attached Files
File Type: zip [Alsco's] Stockrooms Daily Analysis.zip (100.3 KB, 96 views)
Oct 23 '09 #25
NeoPa
32,556 Expert Mod 16PB
I'll look at this Lee, but when I said I wanted to see exactly what was displayed I certainly wasn't after a repeat of the general description of the contents, but the actual values themselves. That way I can repeat the experiment exactly, and not get caught out if the problem is somehow related to the value you chose to test with (rather than the fundamentals of the database).
Oct 23 '09 #26
NeoPa
32,556 Expert Mod 16PB
Try changing line #3 of post #20 to :
Expand|Select|Wrap|Line Numbers
  1. .DefaultValue = Format(.Value + 1, "\#m/d/yyyy\#")
The .DefaultValue property requires a string in the format of a SQL literal.
Oct 23 '09 #27
NeoPa
32,556 Expert Mod 16PB
Actually, as normally, when the default value is already correct, the operator will not update the control, the .DefaultValue property won't be reset in normal usage.

In view of this I suggest a Form_AfterUpdate() event procedure of :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.     With Me.TDate
  3.         .DefaultValue = Format(.Value + 1, "\#m/d/yyyy\#")
  4.     End With
  5. End Sub
This should be in place of the TDate_AfterUpdate() event procedure.
Oct 23 '09 #28
NeoPa
32,556 Expert Mod 16PB
I did some testing and (with the help of MSquared) found that the Form_AfterUpdate event was not the best one to use as it would set the .DefaultValue wrongly when any previous records were edited. Instead I would use Form_AfterInsert.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2.     With Me.TDate
  3.         .DefaultValue = Format(.Value + 1, "\#m/d/yyyy\#")
  4.     End With
  5. End Sub
Try this and let us know how you get on.
Oct 24 '09 #29
lee123
556 512MB
Hey Neopa,

first of all i have to say I'm Sorry for post #23 I didn't understand what was going on. i understand you guys don't have to help but you do and i know this is a free site for people to learn from and for this i'm sorry for not understanding.. and thank you for your help with this database it works great now thanks....

lee123
Oct 24 '09 #30
NeoPa
32,556 Expert Mod 16PB
That's great news Lee.

BTW. It wasn't straightforward and I had to learn it myself properly before I could help, so I'm grateful for the opportunity :) That's two fundamental things I've learned about in this thread. That seems like a good yield to me ;)
Oct 24 '09 #31

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

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
1
by: libsfan01 | last post by:
HI all! ive need to format the date (variable "tomorrow") in this form to mysql format yyyy-mm-dd can anyone please show me how to amend my script? regards Marc
3
by: Liam Mac | last post by:
Hi All, Can anyone direct me or provide advice on how I can assign a null value to a date variable in vb.net. Basically what I'm doing is that I'm looping through a recordset where I have three...
1
kamill
by: kamill | last post by:
Dear members, I want to know about, How to get date of insertion of a perticular data of a table. Is there any query about this. I am using phpmyadmin. Thanks in advance. Regards kamill
3
by: Markus Dehmann | last post by:
I think this is a question about automatic type conversion, but I didn't find the answer after googling for these words ... I have a class called Value (source see below) which can hold an int...
6
by: schlow09 | last post by:
I have been trying to automate certain steps in this database for a company I am working with. I would like to have a query or report run automatically at startup showing all the records that have a...
2
by: Denny | last post by:
I'm going from VB.net. Is there a way to have VS automatically add braces to methods? Also in VB, you do not need to add () for a method or function that does not need parameters. Is there a way...
5
by: mattia | last post by:
Hi, I'm very new to Access...my company decided we need to have a database and I'm somehow trying to get my arms around this... I'm using a 2003 version of Microsoft Access running on Windows...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
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
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...

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.