Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display DateSerial value in text box on form 4

Status
Not open for further replies.

THWatson

Technical User
Apr 25, 2000
2,601
CA
The form is called (currently in design stage) Form3.

1. There is a text box called "txtYear" in which the user enters a 4 digit year.

2. There is a list box called "lstMonths" based on a table. It simply lists the month names January through December.

3. There is a text box called "txtMonth" which will display the month selected in lstMonths.

4. There is a list box called "lstMonthYear" the row source for which is a Select Query which is fed from a table called "tblMonths."
There are actually only 2 fields in the table, MonthYear and Required.
The SQL for the query however extracts the Year, the Month, and uses a DateSerial function to get the first and last days of the month. The SQL is
Code:
SELECT tblMonths.MonthYear, Right([MonthYear],4) AS [Year], Format([MonthYear],"mmmm") AS [Month], DateSerial(Year([MonthYear]),Month([MonthYear]),1) AS FirstOfMonth, DateSerial(Year([MonthYear]),Month([MonthYear])+1,0) AS LastOfMonth
FROM tblMonths
ORDER BY tblMonths.MonthYear;

What ends up getting displayed in lstMonthYear is the MonthYear column, column 0, from the table. The user selects nothing here. The value gets fed from a command button which has the following code
Code:
Dim sql As String
Dim strWHERE As String
strWHERE = "WHERE (Right([MonthYear], 4) = [txtYear]) And (Format([MonthYear], 'mmmm') = [txtMonth]) "
sql = "SELECT tblMonths.MonthYear, Right([MonthYear],4) AS [Year], Format([MonthYear],'mmmm') AS [Month] " _
& "FROM tblMonths " _
& strWHERE & "ORDER BY tblMonths.MonthYear;"
Me.lstMonthYear.RowSource = sql

I have put on the form 2 additional text boxes, "txtStartDate" and "txtEndDate."
In txtStartDate I want to display the first day of the month selected in the process (e.g. March 1, 2009).
In txtEndDate I want to display the last day of the month selected (e.g. March 31, 2009).

I have tried putting the DateSerial serial function as the control source for the respective txtStartDate and txtEndDate text boxes. I have tried adding code to the command button to populate those text boxes. I have also tried putting code on the AfterUpdate event for lstMonthYear but since it itself is populated by code this doesn't work.

The actual end purpose for this form is to display those members who achieved Perfect Attendance in a club for a given month.

Any ideas would be appreciated.

Tom
 
To use Public functions in a query, it's better to put them in a standard module.
 
Works like a charm. I see that you created a new query, "qryPerectStreak" and I didn't realize that I had to build that, thought that I was supposed to run an existing query and interpreted what you referred to as 'qryStreak' to mean "qryStreakBegin". I'm sorry to keep bothering you with this.

This is really fast now!!

Tom

 
I was trying not to be perscriptive of the solution, but trying to show some techniques. Once you calculate the streak start date, there are a lot of different ways to use this information.

Also take a look at the query qryMonthCredit. You can modify that by taking out the parameters. Then you could use it in a form to show different things especially if you use it as a subform.

Set the month to a desired month and you could show everyones status for the month,
required meetings, meetings attended, makeups, and if they are "credited" for the month.

Or you could set a range of dates to the year and set the user ID and show a single person's status for each month in the year.
 
Thanks MajP
I will have some fun playing with the options.

Tom
 
THWatson said:
[blue]I wish there was a better way of getting these columns to line up!! ...[/blue]
There is a perfect way! Its the [blue][ignore][tt] [/tt][/ignore][/blue] operators in Tek-Tips [blue]TGML[/blue] markup language. This provides a [purple]mono spaced font![/purple] ... No porportionality!

What you do is setup your columns in a text editor like NotePad. Just make sure there are no spaces at the end of each line as they'll propagate into the next. Then tag the beginning with [blue][ignore][tt][/ignore][/blue] and the end with [blue][ignore][/tt][/ignore][/blue]. From here its a simple cut & past into Tek-Tips.

[blue]Example Old:[/blue]
MemberID StreakStartMonth StreakLength EndMonth
12 10/1/2007 18 3/1/2009
37 1/1/2008 15 3/1/2009
38 7/1/2008 9 3/1/2009
22 9/1/2008 7 3/1/2009
23 12/1/2008 4 3/1/2009
1 1/1/2009 3 3/1/2009
33 1/1/2009 3 3/1/2009
75 1/1/2009 3 3/1/2009
35 2/1/2009 2 3/1/2009
43 2/1/2009 2 3/1/2009
62 2/1/2009 2 3/1/2009
2 3/1/2009 1 3/1/2009

[blue]Example using tt:[/blue]
[tt]MemberID StreakStartMonth StreakLength EndMonth
-------- ---------------- ------------ ----------

12 10/01/2007 18 03/01/2009
37 01/01/2008 15 03/01/2009
38 07/01/2008 09 03/01/2009
22 09/01/2008 07 03/01/2009
23 12/01/2008 04 03/01/2009
01 01/01/2009 03 03/01/2009
33 01/01/2009 03 03/01/2009
75 01/01/2009 03 03/01/2009
35 02/01/2009 02 03/01/2009
43 02/01/2009 02 03/01/2009
62 02/01/2009 02 03/01/2009
02 03/01/2009 01 03/01/2009[/tt]

I added zeros where necessary to get perfect alignment!

I also intended to post this earlier, but I didn't want to disturb the pace of the thread until you guys were in final.

[blue]Cheers! . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Mornin' TheAceMan1

Gotcha! Thanks for that. I've been coming on here for 9 years and never found that before. Much appreciated.

Yes, MajP and I were on quite a pace. Dunno if we set a record for replies but there were a lot. And MajP was so incredibly helpful that I wish there was a way to give him more stars for all that he did. (need to send him a box of chocolates or something)

In any event, thanks again. And a very HAPPY EASTER to you and yours!

Tom
 
THWatson . . .

[blue]A very HAPPY EASTER to you and yours![/blue] ... [blue]BACK!! [thumbsup2] ...[/blue]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I have over 3000 replies on this site, and still did not know how to line columns up correctly. Thanks Ace Man, my posts will be much neater.

No need for extra appreciation. Always glad to help when it is a good cause like the Kiwanis. I would have been far less helpful if this was a personal database to track your collection of priceless art and sports cars, or a buisness datbase for tracking your issuing of sub prime loans and trading of toxic assets.
 
MajP . . .

[blue]Good Job![/blue][thumbsup2] ... Job of Excellence! ...[thumbsup2]

Certainly [fuchsia]pinky[/fuchsia] inspired!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
MajP said:
[blue]No need for extra appreciation ...[/blue]
[blue]Never deny your worth! ... Ever! ... Sir![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
You may be interested in knowing that the only stuff I do is for churches, service clubs and charitable organizations.

My current project is for the Kiwanis Club of Guelph, Ontario, Canada...and a friend of mine, who is currently the secretary, asked me to design something for him. Another member who is now over 80, has kept hand records for a lot of years and it's time some system was designed for when that chap is no longer able to keep doing it.
It was an interesting exercise to pry data out of the man who has kept the records because this has been his "baby" for so long, and also he's quite mistrustful of computers. We have been able to convince him that the time has come and with some assurance that his historical data is of immense importance we have been able to incorporate attendance data since October 1, 2007, and I think that is good enough at the moment (or maybe good enough period).

There is considerable functionality in the database, but when it came to this Perfect Attendance stuff there was a big block, due in large part to the rather complicated set of rules that Kiwanis uses for determining and thence granting awards for attendance. I knew where I wanted to end up...just couldn't figure out the procedures to get there.

I am not a member of Kiwanis, although I have worked quite closely with this group...principally in emceeing their annual Music Festival final concerts, when the Judges' picks from a bunch of wonderful young musicians gather in our city's entertainment theatre and show their considerable talent.

As time goes on, this database will be of immense benefit to the club, and that's why I noted "extra appreciation" which comes indirectly, through me, from the Kiwanis Club of Guelph.

Hopefully (!!) I can take it from where we are now and finish things off. The suggestions for ways to pull data in a number of ways provide a range of options, i/e...
Code:
[COLOR=blue]Set the month to a desired month and you could show everyones status for the month,
required meetings, meetings attended, makeups, and if they are "credited" for the month.

Or you could set a range of dates to the year and set the user ID and show a single person's status for each month in the year. [/color]

Tom

 
Example

Member Report card for the year. Employee 1

[tt]
MemberID MonthYear Required Attended Makeup MakeUpCredit Credited
________________________________________________________________
1 1/1/2008 5 4 0 0 NoCredit
1 2/1/2008 4 3 0 0 NoCredit
1 3/1/2008 4 4 3 3 Credit
1 4/1/2008 4 4 0 0 Credit
1 5/1/2008 5 5 1 1 Credit
1 6/1/2008 4 3 0 0 NoCredit
1 7/1/2008 5 4 1 1 Credit
1 8/1/2008 4 2 0 0 NoCredit
1 9/1/2008 4 3 1 1 Credit
1 10/1/2008 4 4 6 4 Credit
1 11/1/2008 4 4 1 1 Credit
1 12/1/2008 3 2 0 0 NoCredit
1 1/1/2009 4 3 2 2 Credit

[/tt]

Everyones report card for last month

[tt]
MemberID MonthYear Required Attended Makeup MakeUpCredit Credited
________________________________________________________________

1 3/1/2009 4 4 0 0 Credit
2 3/1/2009 4 0 0 0 NoCredit
3 3/1/2009 4 2 0 0 NoCredit
4 3/1/2009 4 0 1 1 NoCredit
5 3/1/2009 4 3 0 0 NoCredit
6 3/1/2009 4 0 0 0 NoCredit
7 3/1/2009 4 0 0 0 NoCredit
8 3/1/2009 4 0 0 0 NoCredit
9 3/1/2009 4 0 0 0 NoCredit
10 3/1/2009 4 0 0 0 NoCredit
11 3/1/2009 4 2 0 0 NoCredit
12 3/1/2009 4 4 1 1 Credit
13 3/1/2009 4 3 0 0 NoCredit
14 3/1/2009 4 0 0 0 NoCredit
15 3/1/2009 4 0 0 0 NoCredit
16 3/1/2009 4 0 0 0 NoCredit
17 3/1/2009 4 1 0 0 NoCredit
18 3/1/2009 4 3 1 1 Credit
.
.
.
[/tt]
 
Thanks, MajP

You're getting right on to that column line-up tip provided by TheAceMan1. I haven't had a chance to try that trick yet.

Tom
 
MajP
Each day I am more confident in the data that is produced by your sequence of queries.

I am currently building a form and subforms...and from there reports.

I will post something on the 4Share site in another day or two for you to look at.

Tom
 
Here's a link to the further work I have done.

The form to look at is "frmPerfectAttendance." More can be done on this form...but whether or not it's actually needed for purposes other than a form to feed data for reports is debatable.

The one report I have built so far is accessible by the command button on the form.

I wouldn't mind a judgment call about something.
At one point I thought about the possibility of having a "counter" added to one of the tables - probably tblAttendance. This counter field would increment as long as a member met the attendance requirements (based on the rules in the post way up in one of the early posts in this thread) and would reset to zero when 12 consecutive months were attained, or if a month was missed.

However, I am seriously wondering whether or not (1)this is needed, and (2)it would be helpful...given that essentially the same information can be obtained through running the "Perfect in Range" command button on form frmPerfectAttendance, and that could be produced in a report.

The reason I am questioning what to do is this: Let's assume that the secretary runs this Perfect in Range at the end of each month, and makes not of the accumulation of perfect months. This is readily compared to the "Last Perfect Attendance" field to see whether or not a member should be granted another award at this point. If that system is followed, then the "Counter" approach is not necessary.


Any thoughts, words of wisdom about this or alternative approaches, would be appreciated.

Thanks.

Tom
 
The normal rule is that you do not store calculated values, you calculate them dynamically. Some of that has to do with redundancy and storage space. Ex. If you have unit price and quantity, you do not need to store total cost because you can always calculate total cost as unitprice * quantity. Also if values change, then you have to have rules/interfaces to ensure the calculation are redone. So the problem exists that the calculation is no longer current. So I would definitely not store a counter. I do not see any advantage, and the chance of it not being updated correctly exists. The provided function will always provide the current data at any point in time.

 
In frmPerfectAttendance in the database that I posted on 4Share

any idea why I have to press the "Perfect In Range" command button twice to get records to show in the bottom subform? The same thing happens when I try to produce a report using the same query as record source. The first time no records show, and then I press it again and the appropriate records appear.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top