473,471 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Auto Date Detection on Form

283 Contributor
Hello all,

I am trying to create a text box that will automatically create a date based on the day of the week.

What im trying to do is have a text box look at if its Sunday - Thursday to take the current date and add 1 to it if its Friday to add 3 or Saturday to add 2.

Im not sure if this is actually possible or not but what I have been trying to do is I have two text boxes. One that is a constant Date() the other that checks for what day its on and then add accordingly. Problem is even with formating the constant Date() txtBox to only "dddd" it does not want to recognize that its a day of the week I either get a type mismatch error or nothing at all.

Any help would be apprciated

thanks so much,

slen

here is an example of what i have been trying
Expand|Select|Wrap|Line Numbers
  1.  
  2. txtDate1.Defaultvalue = Date()
  3. if format(txtDate1,"dddd", vbWednesday) then
  4.     txtDate2 = txtDate1 + 1
  5. end if
  6.  
Dec 8 '10 #1

✓ answered by mshmyob

Yes that makes more sense. I have attached a sample database for you. See if this helps.

Basically I created a combo box and a text control on the form. The combo box will be dynamically populated based on the current date. It will hold only two dates - the current date and the next processing date based on the info you gave me in the first post. After selecting a date from the combo box the text box will display which date you chose.

This is the code in the ON LOAD event of the form.
Expand|Select|Wrap|Line Numbers
  1. ' ------ populate the date combo box ------
  2.  
  3. Dim strRowSource As String
  4.  
  5. strRowSource = "" ' clear out the strRowSource variable
  6. strRowSource = Date
  7. ' ------- determine the next available processing date based on the current date ----------
  8. Select Case Date
  9.     Case Weekday(Date) = 6 ' friday
  10.         strRowSource = strRowSource & ";" & DateAdd("d", 3, Date)
  11.     Case Weekday(Date) = 7 ' saturday
  12.         strRowSource = strRowSource & ";" & DateAdd("d", 2, Date)
  13.     Case Else
  14.         strRowSource = strRowSource & ";" & DateAdd("d", 1, Date) ' sunday to thursday  
  15. End Select
  16. ' populate the combo box
  17. Me.cboDate.RowSource = strRowSource
  18.  
  19. ' ------ stop populating the date combo box ------
  20.  
This is the code in the ON CLICK event of the combo box.
Expand|Select|Wrap|Line Numbers
  1. Me.txtDateSelected = Me.cboDate.Value
  2.  
cheers,

9 2299
mshmyob
904 Recognized Expert Contributor
To add a certain number of days to a date use the DateAdd function.

Expand|Select|Wrap|Line Numbers
  1. Dim dteDate2 as Date
  2. dteDate2 = DateAdd("d",1,Date())
  3.  
cheers,
Dec 8 '10 #2
slenish
283 Contributor
Thanks for the reply mshmyob,

Ok now with your example how do I make it add the date when its a certain day??
Dec 8 '10 #3
mshmyob
904 Recognized Expert Contributor
Use the Weekday function to determine what day it is. The weekday function will return a number based on the date. ie: 1- for sunday, 2 - Monday etc.

Once you know that then use a Select case to determine how many days to add to the current date as mentioned earlier.

If you need more clarification let me know but try the code first and if you have problems I will correct it for you.

cheers,
Dec 8 '10 #4
slenish
283 Contributor
Hi mshmyob,

Thanks for the quick reply back. So i looked up the Weekday function and from there I ended up getting it to work the way I wanted it to. Im still not sure if I coded it the right way so im attaching my demo for you to take a look at and see if there is any improvments that could be made.

thank you again for the help could not have gotten this other wise

:D
Attached Files
File Type: zip DateTest.zip (11.2 KB, 99 views)
Dec 9 '10 #5
mshmyob
904 Recognized Expert Contributor
Hello Slenish,

I have looked at it and I can clean this up quite a bit for you. Before I do that please explain again what you are attempting to do. For instance what are the hidden dates for? Also can I just create a simple combo box and dynamically populate it for you?

cheers,

P.S.: Actually explain in detail what you are trying to accomplish because your code is very confusing. Maybe if I understood what you are exactly trying to do in detail I can come up with a much better solution.
Dec 9 '10 #6
slenish
283 Contributor
Hello mshmyob,

I appreciate you taking at look at this for me.

Let me break it down in more detail for you. The hidden date fields were for the test. Actually that will become just one txtbox that is hidden that the drop down box looks at to see what the date is then adds 1 to the date depending on the day of the week.

The reason behind this is the program is used for a mail processing. The people using it usually process for the next business day but when the weekend comes they process for Monday.

The drop down menu will give you a selection of two dates (i just put more in to test it for each day) one for the current date and one for the next day date.

hope this helps clear up any confusion :D
Dec 9 '10 #7
mshmyob
904 Recognized Expert Contributor
Yes that makes more sense. I have attached a sample database for you. See if this helps.

Basically I created a combo box and a text control on the form. The combo box will be dynamically populated based on the current date. It will hold only two dates - the current date and the next processing date based on the info you gave me in the first post. After selecting a date from the combo box the text box will display which date you chose.

This is the code in the ON LOAD event of the form.
Expand|Select|Wrap|Line Numbers
  1. ' ------ populate the date combo box ------
  2.  
  3. Dim strRowSource As String
  4.  
  5. strRowSource = "" ' clear out the strRowSource variable
  6. strRowSource = Date
  7. ' ------- determine the next available processing date based on the current date ----------
  8. Select Case Date
  9.     Case Weekday(Date) = 6 ' friday
  10.         strRowSource = strRowSource & ";" & DateAdd("d", 3, Date)
  11.     Case Weekday(Date) = 7 ' saturday
  12.         strRowSource = strRowSource & ";" & DateAdd("d", 2, Date)
  13.     Case Else
  14.         strRowSource = strRowSource & ";" & DateAdd("d", 1, Date) ' sunday to thursday  
  15. End Select
  16. ' populate the combo box
  17. Me.cboDate.RowSource = strRowSource
  18.  
  19. ' ------ stop populating the date combo box ------
  20.  
This is the code in the ON CLICK event of the combo box.
Expand|Select|Wrap|Line Numbers
  1. Me.txtDateSelected = Me.cboDate.Value
  2.  
cheers,
Attached Files
File Type: zip DateTest2.zip (27.0 KB, 106 views)
Dec 9 '10 #8
slenish
283 Contributor
Hi mshmyob,

Very nice! I like how you cleaned that up looks a lot better than what I did. Really apprciate you taking the time to do this.

Thank you very much!
Dec 13 '10 #9
mshmyob
904 Recognized Expert Contributor
You're welcome. Good luck with the rest of your project.

cheers,
Dec 14 '10 #10

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

Similar topics

4
by: Scott Castillo | last post by:
Does anybody know how to auto-submit a form in PHP without Javascript? For instance, submit form variables to self, validate the data in PHP on same page, then, if no errors, auto-submit the data...
9
by: Dwalker | last post by:
I just want to enter today's date in a text input box with the format mm/dd/yyyy when it receives focus. I've been playing around with this but just can't seem to get it to work. Any help would...
1
by: khalid_uk | last post by:
hi can anyone please show me how to put current date in form (drop down) and it should gives the user an error if the want to choose an invalid dates (holidays and past days) and current month and...
1
Virtualmedia
by: Virtualmedia | last post by:
Hi I am writing a dynamic contact form for my website http://www.virtualmedia.co.nz (contactus.asp) everything works okay except that I want to insert an auto date function to record the date and...
2
by: bsmith | last post by:
Having a little problem with a project my boss gave me. We have a web based hosting site that we have multiple databases that the users can connect to. Right now we have it set up that they can...
1
by: mrityunjay11 | last post by:
i want a date selection form in jsp and that variable should be caught in servlet that is how to catch date varible in my servlet. thanks a lot Regards mrityunjay singh
1
by: tmcjunkin | last post by:
I'm trying to back into this project by defining what the user needs to see when they open a form. I'm between beginner and intermediate with vba, but have been using access for years. When the...
10
by: laredotornado | last post by:
Hi, I'm using php 5. Does anyone have any code or a function that auto submits a form that contains a single INPUT, of type = file? Thanks, - Dave
6
by: frys | last post by:
I have a form set up like a journal the top of the page has 2 fields dateID {autonumber) Date (date/time) under these there is a subform with ny notes section
1
by: disney86 | last post by:
I am setting up Forms in Access 08. I have a form which when opened will auto insert the current time and current date. I need to be able to allow the user to set up paramaters to auto select a...
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
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,...
1
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: 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.