How to step through a table one record at a time (1 Viewer)

Gkirkup

Registered User.
Local time
Today, 10:53
Joined
Mar 6, 2007
Messages
605
I have a selection process for various warehouse locations, which results in a query showing those locations. Now I have to print labels for those locations.
I thought the best way to do this is to create a temporary table with the list of selected warehouse locations, and then step through the table one record at a time, until EOF, printing a label for each record.
How do I step through a table one record at a time so I can print a label for that record?

Granville
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:53
Joined
Oct 29, 2018
Messages
13,741
Hi. Couldn't you just base the label report on that query? Do you really need to use code to print each label?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:53
Joined
Feb 28, 2001
Messages
18,742
TheDBGuy is correct, it should be possible to build a report to conform to a standard Avery or other label. However, if that doesn't work, look into doing a MailMerge into Word, which ABSOLUTELY has the ability to build things on standard label sizes.
 

Gkirkup

Registered User.
Local time
Today, 10:53
Joined
Mar 6, 2007
Messages
605
Yes, I have no problem printing the labels. They are actually 20 labels on a page. What I was looking for was the way to step through records in a table and take action on each record.
Thanks. Granville
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:53
Joined
Oct 29, 2018
Messages
13,741
Yes, I have no problem printing the labels. They are actually 20 labels on a page. What I was looking for was the way to step through records in a table and take action on each record.
Thanks. Granville
Okay, to step through records, you could use a Recordset object. You can then loop through the records in the recordset. We can post sample code, if you can't find any.

Sent from phone...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:53
Joined
Feb 28, 2001
Messages
18,742
@Gkirkup - at least for me, there is a conceptual disconnect here. Are you suggesting that you can only print one label at a time due to physical limits on your printer? If so, your question makes sense. Otherwise, it is confusing.
 

onur_can

Member
Local time
Today, 10:53
Joined
Oct 4, 2015
Messages
135
I understood the situation as follows: There is a problem with the record selection, not the label printing, what can be done in this case: Add 1 Yes / No field to the table in the record source and display it in the form, then mark which records you will print. You give the value Yes to the criteria expression of the Yes / No field in the query your tag report is based on.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:53
Joined
Feb 19, 2002
Messages
30,629
What we're trying to say is that, it is more than likely that what you need to do can be done with a report based on your selection query. What other process do you need to do for each record? It is likely that the query or the report can be modified to do calculations for you so that you don't actually need to use a code loop.

While there is nothing wrong with writing code to do this (if you have a very large recordset, which you don't, queries are much more efficient than code loops if they can do what needs doing), Access is a Rapid Application Development (RAD) tool and it is always best to let Access do what Access can do and you only write code when Access cannot do the process either in the query or with the report.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:53
Joined
Feb 28, 2001
Messages
18,742
Back to my point.. I can say it better after some thought. If you want to prepare for printing labels and the printer is able to print them all at once (if it were not for your special handling), you can build a form based on a query that matches the selectivity of the desired report. On a form, navigation assures one record at a time. If you have something to do on each selected record, then your form automatically does the single-stepping for you. After that, your records are ready to go without further intervention.

Put another way, based on your original question: Reports are for continuously printing everything in one operation; forms are for single-stepping through records and making modifications.
 

Cronk

Registered User.
Local time
Tomorrow, 05:53
Joined
Jul 4, 2013
Messages
2,465
Maybe the OP cannot define the selection criteria for a query and wants to make the selection by "eyeball". In that case, I'd provide a multi select list box to select the records for printing labels.
 

Users who are viewing this thread

Top Bottom