Modules & VBA :: Loop In Batches / X Number Of Records At A Time

Jul 4, 2015

I have a form which uses a loop command to output reports as a PDF. The reports take a bit of time to produce and the record set could contain 100-150 records. Any way that you can split the recordset down into batches. Maybe have a button which creates 1-20 and another 21-40 and so on.

View Replies


ADVERTISEMENT

General :: Loop Through Resordset - Download Each Of Records One At A Time

Apr 14, 2014

I'm trying to 'Loop' through a recordset (i.e. "newRS") that has 46 records in it. I get the recordset as follows:

Code:

set newRS = currentdb.openrecordset ("PO Table")
newRS.movefirst

I want to download each of the records, one at a time, into Excel. To do this, I'm use the following:

Do until newRS.EOF = True

Several intermediate steps within the loop that aren't relevant to my problem

Set mySheet = myWB.Worksheets("db POLabel")
mySheet.Range("A2").CopyFromRecordset newRS
newRS.Movenext
Loop

Right after the 'Copyrecordset' command executes, the recordset cursor seems to be jumping to the end of the recordset and I get the following error message (when the code tries to execute the 'Movenext'):

'Run-time error: 3021: No current record'

View 2 Replies View Related

Modules & VBA :: Loop - Copy Current Record By Number Of Times Specified In Quantity Field

Sep 20, 2013

I would like to do a loop but never done one before, basically i want to copy the current record by the number of times specified in a quantity field

So if the quantity field in the record says 5 then copy that record 5 times (I have managed to create the copy and paste code but dont know how to make it do it 5 times

Code:
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPaste

View 2 Replies View Related

Modules & VBA :: Loop Through A Recordset While Adding New Records To Another?

Jun 9, 2014

Is there a way of looping through a form record set, while adding new records to a different form record set? using some data from the 1st record set in the new records?

View 8 Replies View Related

Modules & VBA :: How To Loop Update Query On All Records Of A Table

Sep 2, 2014

I've set a database which has a table in which there are 2 fields "Account" and "Total Accounts". I want to have the amount of total summation of accounts in "Total Accounts" field of each record, which is the result of summation of "Account" values in all previous records till the current one. In order to do this purpose, I copied the value of "Amount" field of each record into "Total Accounts" field of the same record, at first. Then, I tried to add the amount of "Total Accounts" field of every record with just the amount of "Total Accounts" of previous one to earn the actual total amount of that record. I found that I need a VBA loop to do this query for all records (except first record) and so I code it as below, but it has the Run-time error '424' : Object required and it seems that I am in a mistake in definition of strSQL variable:

Code:
Private Sub doDataSegm_Click()
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb()
Set rs = dbs.OpenRecordset("Table1", dbOpenTable)

[Code] .....

View 3 Replies View Related

Modules & VBA :: Loop Through Records And Update Listbox In Each Record

Sep 11, 2013

I have a table with a multi-select listbox as one of the fields. I want to loop through the recordset (table) and changes the listbox selections for each record.

To go into a little more detail, the table (tblEmail) has a field (Label) that is a multi-select listbox. The listbox pulls from another table (tblLabel). I want to loop through records in tblEmail and edit/change the Label(s) for each email though VBA.

I've tried doing something like this:

Code:
With rst
.MoveFirst
Do Until rst.EOF
.Edit
!Label.Selected(0) = True
.Update
Loop
End With

However I get an error that says "Run-Time Error '438' Object doesn't support this property or method" ...

View 2 Replies View Related

Modules & VBA :: How To Loop Through Recordset And Only Attach Records That Are True

Jul 8, 2015

I have some code that loops the clone recordset of my subform and generates a email with attachments. I have mainform and continuous subform within the subform I have field called address this holds paths to files and another field called send and this is a yes/no field

Now what I'm trying to do is loop through the subform if send field is true then attach file from the address path but if send field is false then do not attach file

Code:
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olAttach As Outlook.Attachment
Dim rstAttach As DAO.Recordset

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

[Code] ....

View 14 Replies View Related

Modules & VBA :: Create A Loop To Add New Records And Decrease Amount By One?

Apr 13, 2015

I have the following code that works fine:

Dim db As DAO.Database
Dim rs As DAO.Recordset, i As Integer, ii As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("PatientPrescriptions1")
ii = [RefillAmount]
For i = 2 To ii

[Code] .....

However I am trying to make it decrease the value in [RefillAMount] each time it loops through the addnew function and I can't figure out how to do the rows keep saying the same number:

If I put Refill 3 it creates 2 extra rows and all these rows now say Refills = 2. What I want it to say is

Refills 3
Refills 2
refills 1

And end there. how to do this?

View 2 Replies View Related

Tables :: Limiting Number Of Records At A Time

Sep 9, 2014

I'm trying to create an Access database for my college so that our call centre can allocate students to a specific interview time/date. The problem I'm having is that each interview slot must only have a maximum of 10 students at a time.

I'm creating tables for the student details, address and for each interview slot available.

I'm using Access 2010.

How I can limit the number of records in a table to 10 so that when that interview slot is full it informs the user?

View 14 Replies View Related

Reports :: Loop That Goes To Next Number

Jul 15, 2014

I have created this simple SQL/Query that only show a table of students who passed the exams, but I have to do it manully, like I have to change the range or coordination for every class I have, I want the Query/SQL to loop by itself and goes to the next class/school and gives me the number of all the students who entered the exams and the one's who passed only sorted by school name and class, no more info is required like Student Name or something.this is a very very basic and simple code:

Quote:

SELECT studt.schoolnm, studt.class, studt.fdor, studt.freslt
FROM studt
WHERE (((studt.schoolnm) Like "8") AND ((studt.class) Like "005") AND ((studt.fdor) Like "02") AND ((studt.freslt) Like "0100"));

in other words, I want the SQL/Query to loop by school ID (numbered from 1 to 198 schools) and classes (from 4th to 12th grade entered as 004/005/006/010/012 and so on), the "fdor/freslt" are standers so they must not be changed or looped (if this even possible).
and I want it to be printed like:

School Name | Class | Total Number of Students | Number of who Passed

View 1 Replies View Related

I Want To Print In Batches

Dec 31, 2004

I have a tblClient with about 700 records.
I want to be a able press a button and the first 50 records print and then have a second button that will print the next 50 records so on until all the records are done.

Now the problem is i dont know how to pick each batch of records on its own, and second the client database is always growing so i dont want to have to always add a button that will print the next set of records, also in this situation i would like to have a note for each buttoon saying when it was last cliked so i wont print out the same batch twice.

Now i figure the best solution would be run a a code that will print the first 50 records prompt me to cotinue or to stop. if the stop button is clicked it should register at how many loops it is at so on the next time it runs it skips that amount of loops.
Again im not sure how to pick the records or in this case how to retain the loop info.
Thank you
Mark

View 9 Replies View Related

Assign PO #'s In Batches??

Aug 1, 2007

Hi, all! I'm working on another project and need some advice.

I've got a form where users enter items that will be listed in a budget report. This budget report is submitted to the client for approval. Once approved, these items need to be entered into a PO (purchase order) form and report. There is a checkbox that says approved for PO on the budget form for each record.

What I'm looking for is a way to group the records (that have been approved for purchase) together by vendor, and assign them PO #'s. I know that the end result will be doing an append query that will throw all the records into the PO table, but I don't know how to get the grouping and everything to work.

Does this question make sense? If not, please let me know what info you need. I really need help with this. Any ideas? Thanks!

KellyJo

View 1 Replies View Related

Modules & VBA :: Move 10 Records At A Time Button

Nov 29, 2013

I'm using a form with next record and previous record buttons that works fine but as the size of the database has grown it's clear I need a faster way to move through records.

My solution was to have an advance 10 records at a time button but I'm having problems when reaching the far sides of the records.

For example: If I'm on record 9 and I press go back 10 button then access tries to go to record 0 (which doesn't exist) and brings up and error. The same happens if I try to advance more than total number of records.

I found a solution to this which was to disable the button when the recordcount was less than 10. This works except now if I'm on say record 14 and want to go back to 4, i press the button, i goes back to record 10, the button is disabled so it can't go back further and i get an error.

View 3 Replies View Related

Modules & VBA :: DCount Not Finding Records And Returning 0 All The Time

Sep 10, 2013

It is basically a DCount, and it should find records, but returns 0 all the time. My code is:

Code:

Function cntkit(sftd As Date, sftn As String, typid As Integer, specpaint As Boolean) As Integer 'Counts jobs kitted during shift given by sftd and sftn
Dim timeformat As String
timeformat = "#mm/dd/yyyy hh:nn:ss#" 'need this, to convert it to US datetime format
cntkit = DCount("[JOB]", "Archive", "[Type] =" & typid & " And [Autfinish]=False And [SpecPaint] =" & specpaint & " And ([Kit] BETWEEN " & Format(sftstart(sftd, sftn), timeformat) & " AND " & Format(sftstart(sftd, sftn), timeformat) & ")")
End Function

sftstart and sftend are functions which are returning dates. The funcion works fine if I omit the Between part of the criteria. So the problem is in that part.

View 5 Replies View Related

Modules & VBA :: Fill In A Large Number Of Records

Jul 23, 2014

I need to fill in 200000 records counting from 100000,100001,100002.... and so forth, just one column (and maybe the auto numbering).

make a new DB with these columns: ID, counter
set counter to 100000 where ID=1 (in the first record)
move to next record (or make a new record)
if ID < 300000 then set counter = 1+ (the value of counter in the previous record)
continue until ID=300000

View 8 Replies View Related

Modules & VBA :: Returning Correct Number Of Records

May 3, 2014

I am having trouble with the below returning the correct number of records, and can't see why.

I have one table, tblDevice, which has 4 columns, ID | DeviceRecNo | ExcludeFromCheck | StockLocationID

ID - Autonumber
DeviceRecNo - Number
ExcludeFromCheck - Number (1 = yes, 0 - No)
StockLocationID - Number

I have the following running as part of some code, but it is not returning the correct number of records, and I cant see why not. I have tried creating this in a query in Access itself, and copy the SQL into VBA and it still doesn't return the correct number records.

I have 4 records in there for testing, all with StockLocationID = 3, all with different DeviceRecNo, and two each of ExcludeFromCheck, 2x0 and 2x1

Code:
Public Function test()
Dim db As dao.Database
Dim rs1 As dao.Recordset
Set db = CurrentDb
Set rs1 = db.OpenRecordset("SELECT DeviceRecNo FROM tblDevice WHERE StockLocationID = 3 AND ExcludeFromCheck = 'No'")
Debug.Print rs1.RecordCount
End Function

View 3 Replies View Related

Modules & VBA :: Pull X Number Of Records From A Database

Jan 23, 2015

I need to first generate a random number between 1-4.

Then I would like to use that number to pull that many records out of the database; the records pulled can be random, or whatever.

For example, we have 4 people and my goal is to choose a random # of records to pull for each person. So, for person #1, it might only pull 1 record, then for person #3, it may pull 2 records, etc.

Ideally, it wouldn't pull the same # twice when run for that "session".

After this, I'm hoping to generate all those results into emails (eg for person 3 it would generate 3 emails, etc)

Currently it's all done manually and I think it's doable with Access.

I have some code already for generating "1" email message, but do not know how to pull X number of emails all at once. (X is the random #).

View 2 Replies View Related

Modules & VBA :: Renumber Records When One Number Changed?

Jul 11, 2014

I have a table which has 2 fields 1) Project_Priority_Number and 2) Previous_Priority_Number. If there were 100 records these would be numbered 1-100 in the order that the user originally sets the priority (this number is in addition to the record ID number). I have created a form with code that moves the Project_Priority_Number to the Previous_Priority_Number and then shows the Project_Priority_Number as blank and displays all of the records.

The user can then set new priority numbers in the blank column. Say they choose to make the old priority number 4 the new number 3 and priority 27 now becomes say 2, etc. I want the user to press a button that re-numbers the remaining ones based on their old position + or - 1 (basically to fill the gaps but based on their previous positions). I understand how to renumber if one is deleted but I don't know how to be more specific and re-number based both on their previous priority number and whether something else is now set to replace that.

For Example (the following numbers need to re-order based on previous priority 4 becomming the new priority 1 and the previous number 8 becomming 3 - so the previous 1 becomes 2 and then everything after the new 3 moves forward 1):

PROJECT PRIORITY NUMBER PREVIOUS PRIORITY NUMBER
1
2
3
1 4
5
6
7
3 8
9
10

View 14 Replies View Related

Modules & VBA :: Calculating Number Of Days Between Records

Sep 10, 2013

I am trying to calculate the number of days between incidents.

If I have an incident that happened on the 10th August and another on the 15th August then this would be 5 days, the next incident occurred on the 28th August so that would be 13 days. The problem I am having is how to get access to use the latest date rather than the first date.

View 14 Replies View Related

Modules & VBA :: Count Number Of Records With Date From A Table

Sep 24, 2014

I have a table which specifies the delivery date

I have a from that allows you to choose a year and a month.

I have an unbound textbox which I wan to display the count

I want to be able to count all the records from a table with the year and month specified in the comboboxes and display this in the texbox.

View 4 Replies View Related

Modules & VBA :: Reset Autonumber Each Time Delete / Append Records In A Table?

Oct 25, 2013

I need to reset the autonumber each time I delete/append records in a table. Best way?

View 5 Replies View Related

Modules & VBA :: Create X Number Of Duplicate Records According To A Field On Subform

Jun 13, 2013

I have a code that works great from the parent form but I decided to change the format and call it from a lostfocus event in the subform instead. Now I keep getting error 3314:"You must enter a value in the tbGuests.LastName field".

The code should copy the parent form fields and create x number of duplicate records according to a field on sub-form. It then runs an append query to add the information from the subform.

Code:

Private Sub GuestsInParty_LostFocus()
Dim partymsg As Integer
Dim dbs As dao.Database, rst As dao.Recordset
Dim F As Form
Dim intHowMany As Integer
Dim intCounter As Integer

[code]....

View 1 Replies View Related

Modules & VBA :: Using Temp Variable To Append Specific Number Of Records To Table

May 29, 2014

I need to extract a specific number of records into a table using a MakeTable or Append command using a temp variable, e.g. TempK&SA. Previously on the forum I was shown how code could be added to the OnOpen function to use a temp variable to select a specific number of records to report. ACCESS does not have the OnOpen function in the design view of a query like in the report. It does allow a SELECT TOP but only with fixed variables or percents (e.g. 25 in the code below).

The beginning code for the make table query (where 25 is the number of records added) is:

INSERT INTO [Output] ( RndNo, PointBiserial, BloomsTax, DateRevised, Exam1, Status, Exam2, Exam3, Exam4, [NCCPAKnowledge&Skills] )
SELECT TOP 25 TestBank.RndNo, TestBank.PointBiserial, TestBank.BloomsTax, TestBank.DateRevised, TestBank.Exam1, TestBank.Status, TestBank.Exam2, TestBank.Exam3, TestBank.Exam4, TestBank.[NCCPAKnowledge&Skills], *
FROM TestBank
WHERE (((TestBank.PointBiserial) Is Null Or (TestBank.PointBiserial) Between [TempVars]![TempPointBiserialLow] And .....

how to modify the code to allow a temp variable to determine the number of records to append to another table would be gratefully received. (This process then is repeated for a total of 7 append tables with different temp variables.)

View 7 Replies View Related

Modules & VBA :: Updating Or Adding Records To Form - Find MAX Of Number Portion

Jun 28, 2013

I want whenever I'm updating or adding records to my form, the ID automatically take the value of the previous ID and increment it by 1.

The field type is text (mixed with number) - PM0000000.

I've done some research, what I understand is that I need to:

-do a lookup and
-find the MAX of the number portion.

Name of form - Payment
Name of table - Payment
Name of field - payment_id

I tried these, but to no avail...

Private Sub payment_id_Click()
payment_id = DLookup(("[payment_id]", "Payment", "[payment_id]=Forms![Payment]![payment_id]-1")payment_id + 1)
End Sub

[Code] .....

View 8 Replies View Related

Modules & VBA :: Count Number Of Unique Records Based On Range Of Date

Jan 19, 2015

Code:
' count records in query
Dim rs As DAO.Recordset
Dim db As Database
Dim strSQL As String
Dim beginDatum As String
Dim eindDatum As String
Set db = CurrentDb

[code]....

View 4 Replies View Related

General :: Loop Through Listbox Records

Feb 15, 2014

I am looking to loop through all of the rows in a listbox. For each row in the listbox, I want to check if the last name in the Labor column is contained in any records in the Labor column of a recordset. If it is contained, add the column value to a variable to eventually be shown in another listbox. It seems that the loop is not working correctly and the EstHours is always 0 and the instr function doesn't seem to be working.

Code:
Sub ScheduledHours()
'on error goto errorhandler
Dim LastName As String
Dim FullName As Variant
Dim EstHours As Long

[Code] ......

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved