473,785 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access date functionality

12 New Member
Hi,
I have the following requirements

In a form, there exists a date field which needs to be automatically populated. The date has to be the Friday of every week. Assume in a calendar week Feb 4th - Feb 11th, if the user opens a form for data entry anytime between Feb 4th(Sunday) - Feb 9th (Friday), the data field should populate with Feb 9th date. If the user opens the form anytime after Feb 9th, the date field should populate with the next week's friday's date i.e. Feb 16th.

Can anyone pls help me with this?

Thanks,
Shank
Feb 12 '07 #1
11 2843
maxamis4
295 Recognized Expert Contributor
Take a look at this link it should help you with what you want.

For example this here will return the last sunday
Expand|Select|Wrap|Line Numbers
  1. Week Beginning: DateAdd("d",1-Weekday([GYourdateField]),[YourDateField])
Weekday is an Access built in function.

Good luck
Feb 12 '07 #2
maxamis4
295 Recognized Expert Contributor
Here is some code I made for you. There are really better ways to make this with the date functions but this works too. You can do this on the On Form Load or On Current

Good luck

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSubmit_Click()
  2.     Dim myDate As Date
  3.     myDate = Date ' Date is equal to today's date
  4.  
  5.     ' The weeks starts with sunday which equals 1 Friday = 6
  6.     If Weekday(myDate) >= 2 And Weekday(myDate) <= 6 Then
  7.         Do While Weekday(myDate) <> 6 ' If our date is not Friday's date
  8.  
  9.         myDate = DateAdd("d", 1, myDate) 'Adds a day to my date to find out the date for friday
  10.  
  11.         Loop
  12.         Me.txtWeekofDate = myDate 'Sets your control equal to that date
  13.     Else
  14.         myDate = DateAdd("d", 2, myDate) ' Adds two days to account for the fact that it might be Saturday.
  15.         If Weekday(myDate) >= 2 And Weekday(myDate) <= 6 Then
  16.             Do While Weekday(myDate) <> 6
  17.  
  18.              myDate = DateAdd("d", 1, myDate) 'Adds a day to my date to find out the date for friday
  19.  
  20.             Loop
  21.         End If
  22.         Me.txtWeekofDate = myDate
  23.  
  24.  
  25.     End If
  26.  
  27.  
  28. End Sub
  29.  
Feb 12 '07 #3
NeoPa
32,578 Recognized Expert Moderator MVP
Try setting Default property of the control to :
Expand|Select|Wrap|Line Numbers
  1. =DateAdd("d",7-Weekday(Date(),7),Date())
Feb 12 '07 #4
shankindc
12 New Member
Here is some code I made for you. There are really better ways to make this with the date functions but this works too. You can do this on the On Form Load or On Current

Good luck

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSubmit_Click()
  2.     Dim myDate As Date
  3.     myDate = Date ' Date is equal to today's date
  4.  
  5.     ' The weeks starts with sunday which equals 1 Friday = 6
  6.     If Weekday(myDate) >= 2 And Weekday(myDate) <= 6 Then
  7.         Do While Weekday(myDate) <> 6 ' If our date is not Friday's date
  8.  
  9.         myDate = DateAdd("d", 1, myDate) 'Adds a day to my date to find out the date for friday
  10.  
  11.         Loop
  12.         Me.txtWeekofDate = myDate 'Sets your control equal to that date
  13.     Else
  14.         myDate = DateAdd("d", 2, myDate) ' Adds two days to account for the fact that it might be Saturday.
  15.         If Weekday(myDate) >= 2 And Weekday(myDate) <= 6 Then
  16.             Do While Weekday(myDate) <> 6
  17.  
  18.              myDate = DateAdd("d", 1, myDate) 'Adds a day to my date to find out the date for friday
  19.  
  20.             Loop
  21.         End If
  22.         Me.txtWeekofDate = myDate
  23.  
  24.  
  25.     End If
  26.  
  27.  
  28. End Sub
  29.  

Thanks so much for the quick response. A question on your logic.

//myDate = DateAdd("d", 2, myDate) ' Adds two days to account for the fact that it might be Saturday.

When I did some research, i found that Saturday has a weekday value of 7. I presume your logic works on the assumption that Saturday has a value 0? or maybe my understanding is incorrect? And is there a specific reason you chose the range 2 to 6 for weekday instead of 1 to 6?

Thanks again!
Feb 13 '07 #5
NeoPa
32,578 Recognized Expert Moderator MVP
If you look at post #4 you'll see that this really doesn't need to be this complicated.
Feb 13 '07 #6
shankindc
12 New Member
If you look at post #4 you'll see that this really doesn't need to be this complicated.
Hi NeoPa,
Thanks for your reply. It works fine. Just curious about how the logic works in your case. I understand that Weekday(Date()) returns a number from 1-7 and date add adds a particular # of days to the current date.

In your suggestion, it says
DateAdd("d",7-Weekday(Date(), 7),Date())

Weekday(Date(), 7) - does this take the smaller of the two parameters Weekday(Date() and the value 7? And also, how does it take care that it always updates to the following Friday's date?

Thanks again!!!
Feb 13 '07 #7
NeoPa
32,578 Recognized Expert Moderator MVP
No Problem.
Expand|Select|Wrap|Line Numbers
  1. =DateAdd("d",
  2.          7-
  3.            Weekday(Date(),7),
  4.          Date())
  • Weekday(Date(), 7) returns the weekday number but starting from 1=Saturday rather than 1=Sunday.
  • 7-Weekday(Date(), 7) is therefore, the number of days until Friday. Saturday=1 so 7-1=6. Friday=7 so 7-7=0.
Feb 13 '07 #8
shankindc
12 New Member
No Problem.
Expand|Select|Wrap|Line Numbers
  1. =DateAdd("d",
  2.          7-
  3.            Weekday(Date(),7),
  4.          Date())
  • Weekday(Date(), 7) returns the weekday number but starting from 1=Saturday rather than 1=Sunday.
  • 7-Weekday(Date(), 7) is therefore, the number of days until Friday. Saturday=1 so 7-1=6. Friday=7 so 7-7=0.
Wow! didnt know we could manipulate Weekday function this way.. Thanks for the explanation.
Feb 13 '07 #9
NeoPa
32,578 Recognized Expert Moderator MVP
No problem.
  1. Go to your VBA window (Alt-F11 from the Access window).
  2. Go to your Immediate window (Ctrl-G).
  3. Type in a function (EG. Weekday).
  4. Press F1 for context-sensitive Help.
This can give you information about all sorts of things within Access.
Feb 13 '07 #10

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

Similar topics

1
2637
by: Bennett Haselton | last post by:
I want to get an ASP.Net hosting account with my ISP, and I'm trying to find out what level of access to the server is requried in order for me to view the server in Server Explorer in Visual Studio .Net, where you can see the available database, expand it to get a list of tables, etc. What level of access is required? Of course you need to have an account with the right user rights, but is there some specific service that needs to be...
0
5412
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access Application Block (DAAB) in our .Net projects. We use SqlHelper in SQL based projects, and OracleHelper in Oracle based ones. OracleHelper was not published officially by Microsoft as part of the DAAB but it was given as a helper code in a sample .Net...
1
3111
by: B Moor | last post by:
Hello, I am quite bogged down with this problem and would like some tips/help if any one has any. Thanks in advance. The Problem ----------- This system initially seemed quite stable for a few weeks but now,
6
3926
by: Jean | last post by:
Hi, I am using an Access 2000 front-end to an Oracle 9 backend. I want to write a query that returns all records that are not older than one year for Column "Status_30" (which is a Date). When I look at the ODBC Datasource in Table DWHADMIN_V_PROBLEM , the Date formatting looks normal to me, like #05/07/2005#. However, when I try using the following in my Access Query :
1
1581
by: Eric Girouard | last post by:
Hi A web design client of mine has been developing an Access database with me for the last few months. His intention was to clean up a very messy paper-based workflow consisting of many location / many event calendars. We cleaned up the data, made tables and normalized it. So far so good, the database part works fine. He can find the information he wants when his boss needs him to.
22
6287
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one client (MS Access vs ..NET Windows Forms) would be preferred over the other. While I have some good arguments on both sides, I would appreciate your points of view on the topic.
5
3896
by: Ira Solomon | last post by:
Hi: Any quick opinions on Access 2007? Has anyone got this to coexist with Access 2003? Thanks Ira
5
11654
by: starke1120 | last post by:
Im creating a check in – check out database for RF guns. I have a table that contains models. ID (primary key) Model A table that contains Gun Details ID (primary key) Model_id Gun_Number (assigned gun number by operations)
1
6791
by: scubasteve | last post by:
Looking up values from an Access table is simple. Simulating the 'Range Lookup' functionality from Excel's VLookup formula is a bit trickier. For those that aren't familiar with this, it allows you to look up the next smallest value to what you provided, and return any corresponding field from the table. Very useful for looking up things like currency exchange rates, tax rates, etc., where there might not be an entry for every day/income...
2
2922
beacon
by: beacon | last post by:
Hi everybody, I've searched and searched for the answers to these questions until I've turned blue in the face, so I finally decided to come here for some assistance. Here's the info I'm working with: MS Access 2003 Call log database using data access pages One table called tblCRS_Data_Log Primary key is CallNo An assortment of other fields, including check, text, and combo boxes
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.