How to Open a RecordSet in Access VBA and Loop Through the Records

How to Open a RecordSet in Access VBA and Loop Through the Records

Sean MacKenzie Data Engineering

4 года назад

25,737 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Michelle Baca
Michelle Baca - 23.09.2023 02:43

Do you have anything on how to exit all subs. I have a calls procedure in a module

My call sub imports data with error goto and runs some deletions from tables if error code was 3051 else if not that code then delete data from tables and provides msg box with error code

When I do exit sub it resumes to main module

Please help, I’m learning vba. Self taught

Michelle

Ответить
Jason Fleishman
Jason Fleishman - 18.03.2023 17:03

Watching the 4th time through, it's easy.

Ответить
Laila Satria Suhaimi
Laila Satria Suhaimi - 17.11.2022 02:23

Excellent teaching.Thank you Sir.

Ответить
siclucealucks
siclucealucks - 30.08.2022 18:31

How to loop (and edit) recordset containing a multivalued field?
Eg. Containing the Values ("Express", "Insured") - rst!MultiShipmentType.
In the Table you could either choose both or just one or none. But how to work in the loop with it?
Maybe not the most perfect example but it fits into the above example.

Im looping through a recordset. More precicely im duplicating an existing record where one value has to be changed.
Its a "batch process" - Records have the same values and need to be attached to a bunch of preselected deviceids. however works quite fine until the loop hits a Multivalued field.
Explained in the example from above:
rst!MultiShipmentType = "whatever I pass"
gives me in the Empty source Field case - Error 64224
or if populated with at least one value - Error 3421.
Even if simply pass the source field to it which should have the correct type?
I have also tried .Value but I guess that doesnt work since the table is not normalized.

What I try is copy existing multivaluedfield into a new but within the exsiting table. So im not even altering the type simple A -> B

But I guess its boiling down to how to "address" the multivalued field.
rst!MultiShipmentType(0) ..or rst!MultiShipmentType.Item ...?

Ответить
siclucealucks
siclucealucks - 23.08.2022 14:31

Best Content and not like Richard Rost stuff hidden behind a paywall.
Thx I hope you will have a lot of clicks to get monetized by your marvelous content!

Paypal donate button anywhere?

Ответить
Henry Bruin
Henry Bruin - 18.08.2022 17:14

Most concise explanation of VBA loops and how to use them. I wish I had found this before. Cheers

Ответить
cola man
cola man - 13.08.2022 08:39

Hi Sean, you save my life, I don't know why my coding is not working MS Access 2016 .... after 10 years not coding any more, you highlight the keywords to me dbSeeChanges

Thank you.

Ответить
Doc Doc
Doc Doc - 14.07.2022 16:41

do you have a sample data file of the data base?

Ответить
Mahmoud Barrawi
Mahmoud Barrawi - 21.06.2022 17:02

FANTASTIC VERY SIMPLE AND VERY CLEAR THANKS

Ответить
TAMAL CHAKRABORTY
TAMAL CHAKRABORTY - 07.04.2022 06:20

But, again I have stumbled on generating Defaulters' List. How to generate a list comprising names of defaulters monthwise

Ответить
TAMAL CHAKRABORTY
TAMAL CHAKRABORTY - 05.04.2022 17:03

How to prevent duplicate record while entering data through ms access 2007 form. Roll no & monthly fee should not be entered for a student twice.

Ответить
Shadd Watson
Shadd Watson - 20.03.2022 08:10

This is great information. Thank you for all you do for the community!

Ответить
Yvan Perron
Yvan Perron - 07.02.2022 01:53

Thank you for this tutorial! It is exactly what was looking for!

Ответить
Jason Fleishman
Jason Fleishman - 04.12.2021 16:10

I'm grateful for your generosity

Ответить
DD
DD - 21.11.2021 17:10

I need to loop through an order and make a list of certain characteristics of the order. I tried to create a query, but can't seem to get the correct data. My solution was to create a table to temporarily store the output generated by the loop code, then use that tbl data to perform aggregate operations on the data, then display that data in a report. Finally I use code to clear the tbl of all the data. I looked at some info on 'temp tables ' in MS Access, but not sure if that's the better solution than mine. Any thoughts?

Ответить
Shaun Lawry
Shaun Lawry - 09.09.2021 03:54

Thank you!

Ответить
tamir moav
tamir moav - 10.06.2021 19:34

when I tried the openRecordset there was an error - too few parameters

Ответить
JR SAM
JR SAM - 25.05.2021 12:55

Brilliant explanation. please I got a form Customers and subform sales. I need to duplicate a records. My customers hold customers details like name, address, tel... whereas sales hold details of product barcode of products. I need to duplicate say an invoice. please can you help.. thanks

Ответить
Vishnu Sankaran Kottarappatt
Vishnu Sankaran Kottarappatt - 09.05.2021 08:36

Sir, thank you very much. I have one issue where I have records of one customer belongs to many days with different dates and different quantities. What I want to see that the delivery quantity is increasing between day1 and day2 and so on. So basically I want to see on what percentage is the delivery percentage is increasing for that date and previous date. sample is given below

SERIES DATE1 TTL_TRD_QNTY
EQ 27/04/2021 74870
EQ 28/04/2021 56095
EQ 26/04/2021 44347
EQ 03/05/2021 192281
EQ 04/05/2021 194547
EQ 05/05/2021 61186
EQ 29/04/2021 128921
EQ 30/04/2021 286685
EQ 06/05/2021 165283
EQ 07/05/2021 110032

Ответить