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 Replies


ADVERTISEMENT

Modules & VBA :: Loop Through Table And Create File Names

Oct 22, 2014

I have a VBA routine that runs some queries and then creates a report as a PDF document using my virtual PDF printer. At this point it brings up the Save As dialog and I give the file a name and select a folder to store it in.

But I run this report 30 times for 30 different parameters. The parameters are obtained from a table which contains values such as Cancer, Diabetes, Stroke

-I always name the PDF file according to this value.
-I always choose the same folder.
-I always overwrite the reports I produced last month (copies have been sent elsewhere by then).

how can I get VBA to cycle through this code 30 times, each time selecting the next value from my table and creating/overwriting those files without the need for me to tell it the filename and path?

Code:
Private Sub lstSpecialties_DblClick(Cancel As Integer)

At the moment I am running this code by double-clicking an entry in the Specialty listbox, 'but I would prefer the whole thing to run multiple times for as many Specialties as exist in the table '(currently 30 but could be more in time)

'Warnings off
DoCmd.SetWarnings False
'Make the tables needed for the cumulative queries
DoCmd.OpenQuery "Spec 002 Monthly recruits - part 2 - make table" Each of these queries
DoCmd.OpenQuery "Spec 005 Monthly recruits - part 2 - make table" uses the Specialty selected above
DoCmd.OpenQuery "Spec 022 ABF previous year - part 2 - make table" as a parameter to get
DoCmd.OpenQuery "Spec 025 ABF current year - part 2 - make table" the right data for the report

[code]....

View 5 Replies View Related

Modules & VBA :: Loop Fields Of Crosstab To Create Query

Nov 22, 2014

the below code works fine if i run a crosstab on a whole table however if i pass criteria to the crosstab e.g between [forms]![form]![txtstartdate] and [forms]![form]![enddate] it fails and returns null for every field? even though if set docmd.runquery "qryReductionByPhysician_Crosstab" this opens with the relevant data?

Code:
Set db = CurrentDb
Set qdf = db.QueryDefs("qryReductionByPhysician_Crosstab")
indexx = 0

[code].....

View 7 Replies View Related

Modules & VBA :: Display Amount Of Records On Form

Jul 1, 2013

I want to display on my form the amount of records and which one the form is displaying just like that, which is at the bottom, in text fields.

View 4 Replies View Related

Modules & VBA :: Adding Amount And Checking Daily In Hand Amount?

Jul 21, 2015

I have One table(and designed form from it) in which i have recording the daily transactions(it is like a daily book). Daily transactions took place like Purchase of items of Amount 45, sale=70, sold on account=100 etc.

What problem i am facing is: I would like to Add Cash In Hand amount and would like to show it on my form. When day end I would like to move remaining cash In Hand on separate column of that date. The next day i would like to take the previous Remaining Cash in Hand as Cash In Hand at Start for next date and so on.

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 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 1 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

Create A Loop That Searches Through A Table And Increments A Variable

Apr 22, 2012

Im trying to create a loop that searches through a table and increments a variable every time it finds a record with a specific field set to a specific value. Below is the code but its not working. I then use the variable for another field.This is used in a form btw.

Dim counter As Integer
counter = 0
Set rst = CurrentDb.OpenRecordset("TableName")
Do Until rst.EOF
If rst(10) = "True" Then
counter = counter + 1
End If

rst.MoveNext
Loop
Me.Text24 = counter

View 12 Replies View Related

Queries :: Loop To Create New Tables With Unique Field Values

Sep 20, 2013

I have a table - (Table A) that has 2 fields X and Y. I would like to write a query or script to make two new tables based on the unique values found in field X. In other words, all data where field X = 1 would be written to a new table called "1" and all data wehre field X =2 would be written to a new table called "2".I would like this done automatically.

Table A
Field X Field Y
1 a
1 b
1 c
1 d
2 a
2 b
2 c

View 5 Replies View Related

Reports :: Writing VB Code To Loop Through A List Box And Create Separate PDFs

Aug 19, 2015

I have a sales report that I generate each week based on a query, which relies on the input from a combo box on a form. This works great - but I have select each salesperson, one at a time and run their reports separately.

I'd like to have some code that will run through each person on the list, generate their report, create the PDF, and email (or save) the file.From my initial research, it appears I will need to utilize a List Box (vs a combo box), so I can select multiple salespersons for the report.

I've found a few examples of code to use...but a little lost on how to implement. I create a new form with a list box that queries the property table for the list. I then added a button to execute the code, and attempted to add this (with my control and reports names substituted). Getting all sorts of errors -- so not sure I'm on the correct path.

'Posted by ADezii 5.23.2009 on bytes.com
'Modified by Gina Whipp 11.4.2009 to OutputTo Multiple Files
'Tested in Access 2003 with a Combo Box

Dim intCounter As Integer
Dim cboCode As ComboBox
Set cboCode = Me![ YourControl ]
'If Your Data Type is Numeric use this section

[code]...

View 14 Replies View Related

Modules & VBA :: Unable To Create Duplicate Records On A Subform?

Nov 20, 2013

I am working with a sub-form where once a staff member enters there sub measure I would want to create a duplicate of that record. The problem I am having is that once you enter the sub-form and click the duplicate button it creates a duplicate of the record selected but overwrites the first record in the table. I want it to create a new SubMeasure Number which is the primary key and assigns the record the next available number.

Also if I try to add another record after one has been added I get runtime error "3021" - No current record. I would have to close the form and reopen for it to be able to add again.

I have attached the code below:

Private Sub cmdDuplicate_Click()Dim dbs As DAO.Database, Rst As DAO.Recordset
Dim F As Form
'Return Database variable pointing to current database
Set dbs = CurrentDb
Set Rst = Me.RecordsetClone

[code]....

View 4 Replies View Related

Modules & VBA :: Create Duplicate Records With Incrementing Dates

Jun 27, 2014

I have almost no experience of VBA outside of working a little with codes generated for me like docmd etc.

I am trying to create a database for resourcing staff.
I have a form where the user inputs a start date and an end date which updates a table.
I have a query that works out the number of working days between those dates.
I have a table with all the working dates between now and 2016
I want to put a duplicate record button on the form (I can do that bit)

The tricky part is I want it to create a new record for each date in the dates table between the start and end dates.
Example 23/06/2014-18/07/2014 = 20 working days. I want to end up with 20 records with start dates as below and the same end date.

23/06/2014, 24/06/2014,25/06/2014,26/06/2014,27/06/2014,30/06/2014,01/07/2014,02/07/2014,03/07/2014,04/06/2014,07/07/2014 etc up to 18/07

View 9 Replies View Related

Retrieving The Right Amount Of Records

Dec 6, 2005

I have a table containing the following two fields, one with monthly dates (end of month plus year) and one with profits (per month). However, for some dates the records are missing. For example, for the 31-1-1994 there is no record (not in the date field, nor in the profits field).

How can i create a query that will only show me the records if 10 or more monthly subsequent profits are known, so meaning that in those 10 months no records are missing? So that only the timespans without the gaps (missing records) are shown.

So if the 31-1-1994 and the 30/6/1994 record are missing, then the 4 subsequent records in between those two dates should not be shown,, since the amount of records is not 10 or more. However, if the next missing date would be 30/6/1995, then all the 11 subsequent records between 30/6/1994 and 30/6/1995 should be shown. Since the number of records is bigger than the required 10.

Thanks for helping me out!

Luuk

View 4 Replies View Related

Select First X Amount Of Records

Feb 27, 2008

Hello All

if I have thirty records and have the end user select the first 8 or what ever amount they want, could be 3, 14, 9 etc, is this possible via a form ?

thanks

View 13 Replies View Related

Insert X Amount Of Records

Feb 8, 2008

Hi everybody....

I have a vba question....

I have a form that states how many entries a certain table can have related to that form.

For example:

Form1 - based directly on the table for diagnostic purposes
Cust ID - text - primary key
NumofEntries - number - integer

I want it to create X amount of records in form2 based upon the NumofEntries from form 1 based on table1

For example, I run form 1, and it asks for the custnum, I enter it, and then it asks for the number of entries allowed for the customer, and then I enter it. This number can be different each time. I want the 2nd form just to show that many fields for entry either by a running total (subtraction) in form view or by a for next loop to create X amount of records in the table.

Form1:
CustNum = 1011
NumofEntries = 3

CustNum = 2022
NumofEntries = 4

CustNum = 3033
NumofEntries = 2

Table2
Custnum = 1011, entrynum =1, entry data
Custnum = 1011, entrynum =2, entry data
Custnum = 1011, entrynum =3, entry data
Custnum = 2022, entrynum =1, entry data
Custnum = 2022, entrynum =2, entry data
Custnum = 2022, entrynum =3, entry data
Custnum = 2022, entrynum =4, entry data
Custnum = 3033, entrynum =1, entry data
Custnum = 3033, entrynum =2, entry data

the key is to have the entrynum to start at 1 each time, the rest I can handle.... I am at a loss right now, as I am down to one brain cell, and it's misfiring.....

Granted, tomorrow, when I wake up, I will prolly have a solution, but as always, I value all of your input and design suggestions. Yes, I know already that it's a one to many relationship from table 1 to table 2, I just want some alternate ways to do this. Thanks in advance for any insight you wish to give.

View 3 Replies View Related

Decrease In Performance After Implementing Security

Sep 14, 2006

Have you experienced major decrease in performace after implementing Security in Access? (Note: the database is not encrypted.)

View 6 Replies View Related

General :: Multiply Different Amount Of Hours By Different Amount Of Rates

Jul 17, 2014

I am trying to make a report in which I can see the amount of money that I have to pay weekly to an employee. To explain myself clearer, I have different rates for each employee. For example:

NameNormalPayRateVacationPayRateSickPayRateOvertimePayRateStandbyPayRate
John Smith$15$10$15$30$8
Ken Jonson$10$8$10$20$8

I am doing this in a query. So what I want to be able to do is, for example, take 4 hours that the employee worked at NormalPayRate and multiply it. But if tomorrow the employee worked at a different rate, for example 3 hours overtime, I want those 3 hours multiplied by OvertimePayRate.

The way I saw it on my Google researches, is that they have only one rate and the amount will be [SumOfHours]*[Rate]. But how can I tell my query to skip, for example, one rate because the employee didn't work at that rate that day. So I can have different amount for the different rates.

By the way, entering the information I can divide at what rate the employee worked x day. So if the employee work 6 hours at regular, and later on 4 hours at standby, I have those information separated in my table.

Results that I am getting: I can easily get the amount in money multiplying the whole hours by a rate, so my result in my report will be multiplied by the same rate.

I am using Access 2013 ...

View 2 Replies View Related

Modules & VBA :: Creating Multiple Records Using Button - Text Box To Say How Many To Create

Jul 22, 2015

I am looking for a way to enable a user to fill in a number of fields on a form press a button(CreateButton) and duplicate the records how ever many times is stated in a text box(TxtQty). I also need this to increase the serial number by the amount of times stated in the text box.

There will need to be another text box (TxtNextSerialNumber) stating the next first available serial number

For Example:
TxtNextSerialNumber = AD-Oracle-00010
TxtQty = 5
Press CreateButton to create 5 records
TxtNextSerialNumber = AD-Oracle-00014

5 new records created with the below fields duplicated and the above happening.

I will then need a message box informing the user of the serial numbers created:

'You have created serial numbers AD-Oracle-00010 to AD-Oracle-00014'

Table Name: ADOracle
Form Name: ADOracleTestData

Fields Names:
CustomerName: Duplicate
PartNumber: Duplicate
OrderNumber: Duplicate
OrderDate: Duplicate
HoseKit: Duplicate
Returns: Duplicate
Comments: Duplicate
SerialNumber: + the amount shown in TxtQty starting on next serial number available.

View 6 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

Limiting Amount Of Records In A Table?

Apr 25, 2005

Hey! I'm doing Computing AS level and the coursework is to create a system for "Terry's Turkey". This is basically my first introduction to Access, and our teacher is little to no use!

After alot of work working out things in access and reading alot of books, other than creating the switchboard, theres only a few things left to do!

The first is to limit the amount of "turkeys" that can be ordered. I have 2 tables that this envolves... Order and Customers, they have a one to many relationship (each customer may place one or more orders, each order must be placed by one and only one customer). They are linked by Customer ID. I need to set two limits, I guess by a validation rule of some kind. The first is that each Customer can place no more than 5 orders. The second is that their can be no more than 40 orders in total. A slight complication to this is that a customer can "cancel" an order, in this case its marked as cancelled (theres a yes/no field called Active to determine this), and ideally, these wouldnt be included in the counts.

So far I have the following as a query, though I have no idea how to put this into a validation rule
SELECT Count(Orders.OrderID) AS Var1
FROM Orders;

I guessed that to expand this to not including inactive orders something like
SELECT Count(Orders.OrderID) AS Var1
FROM Orders
WHERE active="yes";

Any help at all would be most appreciated! I have spent many hours pondering over this is and looking at as many access sources that I can! I think this is my last resort :(

View 3 Replies View Related

Selecting Equal Amount Of Records

Jul 12, 2007

I was wondering if someone could help me.
I have a simple table with data that gets updated daily. I need to split the data into 5 equal parts for work distribution. Because the amount of records always changes I can not go by numbering so I need to go by percentage, to split it into 5 ( 20% ) parts. Please help.

View 5 Replies View Related

Tables :: Decrease Field Size But Keep The End Values?

Mar 27, 2013

I have this database where I want to change the field size from 9 to 4 but I want to keep the last 4 digits not the first 4 digits. Is there a way to make that change?

View 10 Replies View Related

Counting The Amount Of Records With The Same Value And A Message Box Response

Sep 15, 2004

Hey. Basically I have several tables. One table (vistiors) has a combo box in one field called Hostee. Each hostee is listed in another table with all their information. When a hostee is selected in the hostee field of the visitors table I simply need it to count how many people including the currently selected person are being hosted by the person and check if it is greater or less than the amount of people set in the host table which has a field called Limit that has a number which is the maximum amount of people one person is willing to host.

If its greater than the amount in the host table a warning message should come up informing the person (but still allow the assignment to occur.)

As a note I have the combo box set to show the first name of the individual but select both the first name and ID

the code is below for the row source:

SELECT [Hosts].[First Name], [Hosts].[id] FROM Hosts;

If someone could tell me how I could get it to show multiple things within the combo box that'd be great.

IE Right now it shows just a first name liek Alex, Rachel, Bill. I'd like it to show the first name as well as the last name and a third additional field. IE Alex Lastname T1 or Rachel Lastname F4 etc.

Can anyone show me the general code to do this? I do know some VB but I'm used to using SQL with PHP primarily. I am new to access and only know it vaguely. Thanks in advance!

View 2 Replies View Related







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