473,397 Members | 2,116 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.

Using SQL to find a date in a table to use in VBA

56
I've got a table that is full of loads of lines of data. I want to pluck off the most recent date and I believe I'm going at this in a very long winded and overly complex fashion.

What I have so far is:

Expand|Select|Wrap|Line Numbers
  1.     Set cnn = CurrentProject.Connection
  2.     Set rstVali = New ADODB.Recordset
  3.  
  4.     With rstVali
  5.         .Open "SELECT Max(AllTransactionData.[Transaction Period]) AS [MaxOfTransaction Period] from AllTransactionData", cnn, adOpenForwardOnly, adLockReadOnly
  6.     End With
  7.  
Which runs a query that returns to largest date in the Transaction Period column.

Now what I'm not sure how to do is refer to this in the code.

My aim being is that I'm writing a search function that will find x amount of months worth of data from the most recent piece of data backwards. I can get it running from todays month/year but the data may not always be as up to date as that. I need it to run from where it is up to so far.

Thanks for helping me though my various headaches guys!

Si->
Aug 9 '07 #1
4 1210
Rabbit
12,516 Expert Mod 8TB
The DMax function will return what you want as a string.

DMax("[Transaction Period]","AllTransactionData")
Aug 9 '07 #2
FishVal
2,653 Expert 2GB
I've got a table that is full of loads of lines of data. I want to pluck off the most recent date and I believe I'm going at this in a very long winded and overly complex fashion.

What I have so far is:

Expand|Select|Wrap|Line Numbers
  1.     Set cnn = CurrentProject.Connection
  2.     Set rstVali = New ADODB.Recordset
  3.  
  4.     With rstVali
  5.         .Open "SELECT Max(AllTransactionData.[Transaction Period]) AS [MaxOfTransaction Period] from AllTransactionData", cnn, adOpenForwardOnly, adLockReadOnly
  6.     End With
  7.  
Which runs a query that returns to largest date in the Transaction Period column.

Now what I'm not sure how to do is refer to this in the code.

My aim being is that I'm writing a search function that will find x amount of months worth of data from the most recent piece of data backwards. I can get it running from todays month/year but the data may not always be as up to date as that. I need it to run from where it is up to so far.

Thanks for helping me though my various headaches guys!

Si->
Hi, Widge.
Expand|Select|Wrap|Line Numbers
  1. dteSomeVariable = rstVali.Fields("MaxOfTransaction Period")
or somewhat faster
Expand|Select|Wrap|Line Numbers
  1. dteSomeVariable = rstVali.Fields![MaxOfTransaction Period]
or simply
Expand|Select|Wrap|Line Numbers
  1. dteSomeVariable = rstVali![MaxOfTransaction Period]
as soon as Fields is default property of Recordset

BTW I think DMax function would be more simple solution.
P.S. You could find this viewing ADODB.Recordset in object browser. Properties/methods naming is quite intuitive and help is available as well.
Aug 9 '07 #3
Widge
56
The DMax function will return what you want as a string.

DMax("[Transaction Period]","AllTransactionData")
Wonderful. I had dived in with an overly complex method! Thank you!
Aug 10 '07 #4
Rabbit
12,516 Expert Mod 8TB
Wonderful. I had dived in with an overly complex method! Thank you!
Not a problem, good luck.
Aug 10 '07 #5

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

Similar topics

6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
3
by: sean | last post by:
I have a table with fixed row of records SORTED by DATE using ADO pagination method. The user can click a link in one table cell and go to another page to modify the record. Once the updated record...
5
by: cover | last post by:
I have an input form that passes data when submitted to a second form to let the user know what they have just entered into the db. My question comes with using 'update'. I'd like to query the...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
0
by: Keith | last post by:
I have a web form that contains a repeater control that is designed to ask like a check book register. Clicking on a certain transaction takes the user to a different .aspx page where it can be...
0
by: Keith | last post by:
I have a web form that contains a repeater control that is designed to ask like a check book register. Clicking on a certain transaction takes the user to a different .aspx page where it can be...
3
by: anthonybrough | last post by:
I have an asp page that has a form to collect user data in a form. when the user clicks submit the input is validated. If any fields are not acceptable the user clicks on a button to go back to...
14
by: jcage | last post by:
Is there any tutorials online for sending email through forms? I can send an email as well as write to my MySQL database from home with the following code but not at work. I think there might be...
1
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >=...
7
by: nhkam | last post by:
I am using MS Access 2007 I have a transaction table which holds all records with posting date on each of them. I used a make table query to find out the max date hold in the transaction table and...
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
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...
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
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
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,...

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.