473,378 Members | 1,410 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,378 software developers and data experts.

HowTo: for each record in query result do some VBA code ?

Another question I've always asked myself:

Is there any possibility to do some sort of "for each record in query result A do some VBA code (e.g. call a VBA procedure)?

Best regards,
D.R.
Feb 21 '10 #1
5 5139
NeoPa
32,556 Expert Mod 16PB
Indeed.
  1. Open the QueryDef as a recordset in your code. I typically use the DAO option for this, but there is an ADODB version available too.
  2. Process through the recordset using MoveNext().
  3. Call your code within each iteration of your loop.
  4. Continue While Not .EOF or Until .EOF.
Feb 21 '10 #2
NeoPa
32,556 Expert Mod 16PB
Depending on exactly what you require, there is also the option of calling a function (NOT subroutine. It must return a value) as part of the query itself. It would have to be defined as Public in a standard code module, but as well as determining a value for you, you could get it to go off and dance somewhere too.
Feb 21 '10 #3
Wow, thanks again for your answer! I googled QueryDef and found enough information.

Question: Are there any (maybe hidden) problems, when using QueryDef with access tables connected to mysql (linked table).

Best regards,
D.R.

PS: There should be some kind of "thank you"-button, so anybody can see that you're giving very good and quick answers. Maybe you should become an Access MVP :)
Feb 22 '10 #4
This time I hope I'm not bumping too early.

One question is still open:

Are there any (maybe hidden) problems, when using QueryDef with access tables connected to mysql (linked table)?


Best regards,
D.R.
Feb 23 '10 #5
NeoPa
32,556 Expert Mod 16PB
@Poweruser
First let's look at the term QueryDef. Since you need to Google it, it must not be as obvious as I'd expected. QueryDef is simply the correct term for the queries that are saved in an Access database. Every saved query is a QueryDef. A Query is a looser term which covers QueryDefs, but also SQL strings called from within code in Recordsets etc.
@Poweruser
The bump is probably not too early, but as I haven't yet had a chance to look at your previous post, was probably unnecessary. Certainly not a problem. For your peace of mind though, remember that forum based web posts are picked up as and when by various different members. For instance, I may well take a few days off sometimes if I go away from home for any reason. A lack of response for many hours, or even a day or two, doesn't necessarily mean a lack of interest or intention, just that this has to fit in with other things.
@Poweruser
One thing to bear in mind, is that the fact that this is managed by a back-end server means that any permissioning done there will effect such queries. One user may have different rights from another, so it may work correctly for one but not the other. If you're using linked tables though (where the linking is managed outside of the QueryDef object), it should all work pretty smoothly.
@Poweruser
Very kind of you to say so, but from what I see of the Access MVPs, they contribute more than I do at a professional level. This is just a hobby for me. I enjoy it of course, but cannot devote enough time to it even to be considered for that.

On the thanking side, a little note of thanks, as you've done, is always well appreciated :) Aside from that, if you feel an answer (post) particularly hits the spot then you can select it as the best answer. It's always nice to see one of your posts has merited that.
Feb 23 '10 #6

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

Similar topics

3
by: Jack | last post by:
Hi, I have a form when loaded, retrieves record from an access table. Among other fields there is a check box called FinalUpdate. This is tied to a field in Access of type Yes/No. The form...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
3
by: Simon2005 | last post by:
Hi, This is a segement of code taken from Warren Young's FAQ on Winsock @ http://tangentsoft.net/wskfaq/ struct Connection { SOCKET sd; char acBuffer; int nCharsInBuffer; Connection(SOCKET...
1
by: Kevin.S.Campbell | last post by:
Greetings, I'm trying to run a sql query on a continous form. I have the query working correctly the way I want it. I want this query to be displayed on the form in the text box on the load...
9
by: MLH | last post by:
I have a source query (qryITSLetterList) feeding rows containing name, addr, city, state, zip and VehicleID to a report (rptITSnotices). The query may contain 1-to-5 records resulting in 1-to-5...
5
abouddan
by: abouddan | last post by:
Hi all I am working on an accounting project using MS Access 2000, that demands to calculate many fields in a spesific record. The problem: The query I am using returns many records and for each...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
6
by: Winbug | last post by:
hi I have a scenario where I have created a stored procedure wich task is to search in my database with certain criterias. For each record from this search, I want to run a couple of other stored...
7
by: ggfota | last post by:
I have problem creating Access (Continuous) Form with indepenent CheckBox for each record. The user should be able to select records that will be processed by VBA based on ChceckBox value. When I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.