473,405 Members | 2,210 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.

Access Query directly into Recordset (VBA)?

Ahoy! I'm hoping for some help on what (I believe) should be a simple task.

I have a form with a button. I would like that button to have a caption with a date. That date should be pulled out of a table when the form loads. (e.g. the button would read "Last Audit was 2006/12/21" - that date is on my "Audit" table).

I created an actual query object to return the largest date on the Audit table. I'm trying to find a way in VBA to open read the 1 record, 1 field from that query when the form loads. I thought I could just load it into a recordset and use the button.caption to set it - but I can't even figure out how to open an Access query (in Access) without displaying the query some way. I just want to get the value from that 1 field, then set the button's caption.

(I used a query object instead of a VBA-hard-coded SQL statement just in case I want to change the query without digging through my VBA code)

I used to be good with Access, years ago before falling in love with MySQL and MS SQL Server. Now - I need help. Much Thanks.
Dec 28 '06 #1
3 7008
Ahoy! I'm hoping for some help on what (I believe) should be a simple task.

I have a form with a button. I would like that button to have a caption with a date. That date should be pulled out of a table when the form loads. (e.g. the button would read "Last Audit was 2006/12/21" - that date is on my "Audit" table).

I created an actual query object to return the largest date on the Audit table. I'm trying to find a way in VBA to open read the 1 record, 1 field from that query when the form loads. I thought I could just load it into a recordset and use the button.caption to set it - but I can't even figure out how to open an Access query (in Access) without displaying the query some way. I just want to get the value from that 1 field, then set the button's caption.

(I used a query object instead of a VBA-hard-coded SQL statement just in case I want to change the query without digging through my VBA code)

I used to be good with Access, years ago before falling in love with MySQL and MS SQL Server. Now - I need help. Much Thanks.
Looks like you are looking for the dlookup function, something like:
Expand|Select|Wrap|Line Numbers
  1. cmdButton.caption = DLookup("[Date], "QueryName")
You'll have to change the names here, obviously. That should be sufficient if your query only has one record. Just put it in your Form_Load event
Dec 28 '06 #2
NeoPa
32,556 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. cmdButton.Caption = DMax("[Date]","Audit")
Dec 30 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Try :
Expand|Select|Wrap|Line Numbers
  1. cmdButton.Caption = DMax("[Date]","Audit")
You won't need your query with the above solution either it will do it all in one go.

Expand|Select|Wrap|Line Numbers
  1. cmdButton.Caption =  "Last Audit was " & DMax("[Date]","Audit")
  2.  
Mary
Jan 1 '07 #4

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

Similar topics

2
by: Rigid Kitten | last post by:
I cannot figure out how to: 1. call an Access query from C# and consume the recordset, where the query uses a user defined function. for example select rowid, GetBreedOfCat() from tblCats; ...
1
by: David | last post by:
Hi everyone. I have read every page that Google returns on this topic, but can't find anything that resolves my problem. Basically, I have an Access Database that does a number of different...
2
by: SenseForAll | last post by:
First please note I am a novice at VBA and not even that experienced with DAO/ADO and MS-SQL. Any assistance is appreciated. That said... I have an application written in Access w/ VBA. I need to...
2
by: Alicia | last post by:
If I wanted to create a table by hand create table temp( etc, where do I do it in access?
6
by: Mark | last post by:
Hello. I have an MS Access 2000 form whose fields I need to read and write from VBA. The fields are data-bound, using a query that has been defined and saved in my Access database. The query...
5
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
0
by: Rob | last post by:
Hey folks, my mind is turning into mush... I created a report tracking program in access that works beyond my greatest expectations. So of course, I am constantly adding features to make life...
0
NeoPa
by: NeoPa | last post by:
Many of us have noticed that there are some very useful functions available to you when using Excel, but these same functions are not available, as standard, in Access. A particular issue I had...
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
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,...
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
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.