473,405 Members | 2,187 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,405 software developers and data experts.

Extract max date and use the value in a line of code

Iam a complete novice to writing code so I started with a snippet of code that produced what I wanted and have been add to it and modifying bits to get where I want to be.. so my code maybe a little disorganized..sorry.

I have a MS Access Function which ranks a Queries results and is working fine. I have been able to add text to the beginning of the output script. I am now trying to insert a date into the text. Specifically I want the highest date from the records selected by the query. Ive been using (max[MaxOfShootDate]) which maybe completely wrong, MaxOfShootDate is the field name containing the date info.
I added Dim strQry As String to hold the value
dtRank is the placeholder of the value I want.
The part of the date I require is only the MONTH that why the Format(dtRank, "mmmm") is there.

Expand|Select|Wrap|Line Numbers
  1. Function PBTotal(ByVal dtRank As Date, ByVal boolRanked As Boolean, Optional intTop As Integer = 0) As String
  2. Dim qdf As QueryDef
  3. Dim rs As Recordset
  4.  
  5. Dim strRank As String
  6. Dim strQry As String
  7.  
  8. strRank = "The highest personal best scores up to " & Format(dtRank, "mmmm") & " were: "
  9.  
  10.  
  11. Set qdf = CurrentDb.QueryDefs("PB5")
  12. strQry = "Select (max[MaxOfShootDate]) FROM [PB5]"
  13. strQry = dtRank
  14.  
  15. Set rs = qdf.OpenRecordset
  16. Do While Not rs.EOF
  17.  
  18.     strRank = strRank & rs.Fields("Member") & " " & rs.Fields("MaxOfMaxOfShoot1") & "; "
  19.     If rs.AbsolutePosition = intTop - 1 Then Exit Do
  20.     rs.MoveNext
  21. Loop
  22.  
  23. Set rs = Nothing
  24. Set qdf = Nothing
  25.  
  26. PBTotal = strRank
  27. End Function
  28.  
Appreciate any help.. baby step please
May 30 '12 #1
4 1871
Try using the function DMax. You can look it up in help for a better description of the syntax. It should look like this.

dtRank = DMax("MaxOfShootDate", "PB5")
May 30 '12 #2
Hi Marc
Thanks for the reply
Your code returned the same answer as mine = April.. I need the answer to equal May.
I checked the Query PB5 and it contains April and May dates.. any ideas?
May 31 '12 #3
I have created what I want to see as a result in a Query, ie: May
Expand|Select|Wrap|Line Numbers
  1. SELECT Max(Format([MaxOfShootDate],"mmmm")) AS [Month]
  2. FROM PB3
  3. WITH OWNERACCESS OPTION;
  4.  
  5.  
Is there any what to adapt this to run in my Function in place of
Expand|Select|Wrap|Line Numbers
  1. dtRank = DMax("MaxOfShootDate", "PB5") 
  2.  
I tried this which didn't work
Expand|Select|Wrap|Line Numbers
  1. Set dtRank = (Format("MaxOfShootDate", "mmmm", "Month", "PB5"))
  2.  
Anyone any ideas please
Jun 1 '12 #4
OK
I have now gone down the path of trying to create a Public Function to get the value from Query PB7 and plug that answer [which is "May"] into my line of text.
Here is my code so far:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Public strgOutPut As String
  4. Public QueryMonth As Variant
  5. Public Function GetGlobal(VariableType As String) As Variant
  6. Select Case VariableType
  7. Case GlbValue
  8. Case "PB7"
  9. GetGlobal = Month
  10.  
  11. End Function
  12. Sub RankTest()
  13. Debug.Print PBTotal(#5/20/2008#, True)
  14. Debug.Print PBTotal(#5/20/2008#, False)
  15. End Sub
  16.  
  17. Function PBTotal(ByVal dtRank As Date, ByVal boolRanked As Boolean, Optional intTop As Integer = 0) As String
  18. Dim qdf As QueryDef
  19. Dim rs As Recordset
  20.  
  21. Dim strRank As String
  22. Dim strQry As String
  23. Dim max As VbDateTimeFormat
  24.  
  25. strRank = "The highest personal best scores up to " = strgOutPut & " were: "
  26.  
  27. Set qdf = CurrentDb.QueryDefs("PB5")
  28.  
  29.  
  30. Set rs = qdf.OpenRecordset
  31. Do While Not rs.EOF
  32.  
  33.     strRank = strRank & rs.Fields("Member") & " " & rs.Fields("MaxOfMaxOfShoot1") & "; "
  34.     If rs.AbsolutePosition = intTop - 1 Then Exit Do
  35.     rs.MoveNext
  36. Loop
  37.  
  38. Set rs = Nothing
  39. Set qdf = Nothing
  40.  
  41. PBTotal = strRank
  42. End Function
  43.  
The way I written it I get a date value of 05/06/12, where I am expecting "May"
Can anyone help me now?

Paul
Jun 7 '12 #5

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

Similar topics

1
by: Pooja Raisingani via AccessMonster.com | last post by:
Hello, Can anyone please tell me How to use a select query to extract date from a Datetime field in Access 2000?? Thanks -- Message posted via http://www.accessmonster.com
5
by: darrel | last post by:
I have the following right now to enter a date into SQL getting the data from some pull down menus: ------------------------------------------------- dim dateCCJApprovedDate as DateTime if...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
3
by: Bharathi | last post by:
Hi, I got strucked with reading date value from excel file using C#.NET. For Jan-2000 the value I am getting is 36526.0. For all other dates also I am getting some double value like this. ...
4
by: luthriaajay | last post by:
Hi, I need to use XPATH to extract the value of attribute ID in element Instrmt <?xml version="1.0" encoding="UTF-8"?> <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4"> <Order...
2
by: luthriaajay | last post by:
I need some help to extract the LatestFillQuantity element value using XPATH. in Java. I am unable to extract the value of 10000. Please help as to what have I done wrong.? Help appreciated. ...
2
by: rahul dasgupta | last post by:
I Am Doing A Project In Which I Require To Extract A Whole Line From A File And Display It To The Console......... How Can I Do It. Plz Help Me Its Very Urgent I Have To Submit On 31st July
8
by: poolboi | last post by:
hi guys, i just did printing to a certain file #!perl\bin\perl use strict; use warnings; my $t; my @ok;
5
by: sbettadpur | last post by:
hello Let me explain first the table structure. table - > pds fields - >District_ID, W_ID, Commodity_ID, Distribution_Cat_ID, Date, OB, Closing_Stock here i want the Closing_Stock value...
9
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
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.