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
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
I have a table that has a primary key that does an autonumber in increments. Then I made some queries that will append records by date and then also another query that will delete what was appended. Then I created a reverse sequence of this process in case I change my mind and would like to put back the records I archived, however, when I do this, the primary key is now thrown off and will still revert to the last primary key that was appended before the archive ever took place. In other words it still thinks that the records I appended before I did the reverse, are still there. So now it will not let me save the record because it is a duplicate.
Is there a way to set the autonumber for the primary key to where I want it to begin?
Does anyone know how I can create a form which asks for the name or lastname of the customer and does a search throuout the database and brings up all that customers informtation. And if their is more than one thats are the same you can switch through them untill you find the right one.
Dim var1 As Variant, var2 As Variant, var3 As Variant, var4 As Variant DIm var5 As Variant, var6 As Variant, var7 As Variant, var8 As Variant Dim var9 As Variant, var10 As Variant Dim i1 As Long i1 = 1 Do Until i1 > 10 var & i1 ??? = "0" & i1 & "." & txt1 & "." & txt2 i1 = i1 + 1 Loop
How to make concatenate var + i1 to make loop function?
I am relatively new to VBA and have this loop (see below) was wondering if it was possible to build it into a variable, so I could call upon it within an IF statement.
Set ctl = Me.listSeeAllAssets For Each varItem In ctl.ItemsSelected rs1.AddNew rs1!AssetNo = ctl.ItemData(varItem) rs1!DateOfService = Me.DateOfService
I some code that is reading the first 32 lines of a text file and paste the results into 1 text box on individual lines. I would like each line to go into an individual text box.
I have 32 text boxes named txt_1, txt_2, txt_3 I have a variable named ThisLine holding the line of the text file. I have a variable named textBoxName holding the name of the control.
Need to putting these together to write the line to a text box .
Code: Sub ReadFile() Me.txt_newData = "" Me.txt_OrigData = "" 'again, we need this strange thing to exist so that ... Dim fso As New FileSystemObject
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
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
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
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
I have created a form that searches a table to show certain criteria. I am having trouble with a part where the table uses a checkbox and I am trying to use a combo box on the search form to return the results based on is it checked? Yes/No or both. When I test it I keep getting Runtime error 3075 missing operator.
The sql I am using is below and when I try and see where it is going wrong it highlights the line.
Code : Me.Filter = strWhere
Code: Private Sub cmdFilter_Click() Dim strWhere As String Dim lngLen As Long Const conJetDate = "#dd/mm/yyyy#"
I'm having a problem with my autonumber. Whenever a new record is created, it increments the ID by 2, not by 1. So my frist 4 records are: 1,3,5,7 (not 0,1,2,3). As far as I've seen, I can't set the increment number to 1 (it seems to be defaulted to increment by 1 all the time). Anyone know anything about this problem?
Haven't been able to find an answer to this one. I have a subform that is related to the main form by order number. In the subform, user will enter qty received for a po. Because we may not receive entire quantity for po at once, we need to add a number or letter to the end of the order number to indicate more than one received qty. So order number 1234 would be 1234-1 for first quantity, then 1234-2 for second qty. Does anyone have any ideas on how to accomplish this? Thanks for any help. I am using Access 2000.
I have a folder which holds 1000s of pictures organised in subfolders, for example:
D:~AI Database Print Scans2009family and D:~AI Database Print Scans2009holiday
And so forth. In total at the moment 17 main subfolders, each of which hold another 2-3 subfolders.
I am putting together a database to bring pictures together with all sorts of details. I import the picture via hyperlink and complete the various fields. All that works fine but there are a lot of pictures! And it gets confusing to see which ones have already been entered into the database and which ones haven’t.
One solution for this is to copy the pictures that have been “completed” to another folder. I have found a way to do that:
Dim fs As Object Dim oldPath As String, newPath As String oldPath = Forms!frmPrintDetails.txtPath1 newPath = "D:~AI Database Print ScansCompleted_Entries" Set fs = CreateObject("Scripting.FileSystemObject") fs.CopyFile oldPath, newPath Set fs = Nothing
Works fine, but the problem is that I loose the subfolder structure, it copies all pictures to the same main folder. I’d like to maintain the subfolder structure and add code to create the correct subfolders and next copy the picture. With the different paths I’m lost. I don’t know how to extract the correct path in code. I’d also like to either rename or remove the picture once I have completed entry of the details. The problem I have again is that I don’t know how to code for a changing path.
I am trying to set up something to be able to take me to a folder that holds various forms for personnel. I have a query that generates the link for each person. I have tried to set it up as a hyperlink in ACCESS 2013 and it displays as one but doesn't act like one.
I want to be able to click the link and have it open up a personnel folder for that individual. I can't find a MACRO that I can create to do it. Example of my query is that it creates a link K:Main BreakdownSection BreakdownPersonnel FoldersName and the name is the variable part.
My next problem will be to have it create that folder when we have new personnel arriving.
I would also note that I have not worked with ACCESS in many years and much of what I was able to do with 2002 and 2003 doesn't work with the newer versions of ACCESS.
I want some VBA code that can loop through the table above one by one returning the value. The table data will change so i would like the code to handle change as well.
I want the returning value to be returned has a string i.e. TblValue = <table data value>
Because then i want to use the value to be put in this sql query- DoCmd.RunSQL "INSERT INTO TEST_DOC SELECT * FROM " & [color:red] TblValue [/color]
I have a table named tblItems with a field "Qty".I have another table, tblItemsSold, with fields "InvNo" for invoices number and "QtySold".Both have UPC (barcode) fields.What I need to do is when the "Complete" button is clicked: All the Items (by UPC) with the same invoice number (InvNo) need to subtract the "QtySold" in tblItemsSold from "Qty" in tblItems.I would like to do this through VBA so I can just plug it into the existing code I have.
Please could someone enlighten me on the following scenario I have.
I would like to get from a button click the information from Sheet_subID (cat_parameter) copied into the Main sheet Description field. I think this maybe would be done with a loop? Taking one from in tunr from Sheet_subID and then putting it into the description filed until al cat_parameters have been copied.
This information is not beng duplicated as such because the text that lands in the description field will be modified slightly by the user. The information contained within the Sheet_subID are for presets for in the case below Compensator Setting 3. Compensator 1 would have different presets.
Could someone check the following code. i've set up a form for creating regular bookings, and have a field, for which you type in the frequency in days you want the bookings for. (ie, 7 days for every week on that day, 14 for every two weeks etc...) and it seems to work, however it just alters the one record, instead of creating entirely new ones. Could someone please help:
Private Sub cmdCreate_Click() Dim date2 As Date Dim period As String Dim cost2 As Currency Dim frequency2 As Integer
Do While year = actual_year
date2 = Date_For period = Time_Period cost2 = Cost frequency2 = Frequency
Date_For = date2 + frequency2 Time_Period = period Cost = cost2 Frequency = frequency2
DoCmd.Close acTable, "tblRegularBookings" Loop
End Sub
Also, one of the other problems i'm trying to solve is for those who want to create a regular booking but on say every third monday of the month for example.
Hi, I need help with inputting multiple values in a table I am using below statement in asp file and it works fine, when I input one value of name in form , as it takes that value and just input into the table. If it already exists then it just displays error message that this name value already exist in table as name field has no duplicate checked. I need to input multiple records now instead of just one. The current statement I am using is
<% Name = replace(trim(Request("Name")),"'","''")
SQL = "Insert Into table(tableName) Values('" & Name & "')"
objCon.Execute SQL
%>
But now I want to send multiple values from the text box instead of just one value, so I need a loop here. The values in the text box are separated with enter. Please let me know how do I run this query in loop that it will input one name first and then input the second value and then third so forth. (input multiple records instead of just one). Can you please give me the SQL statement for ACCESS or asp querry.
And then called this join as a symbol or variable, and then have it use to select the items from these joined tables, can this be done in Access? Here is an example of a code that I created, but it has an error message saying the FROM syntax is incorrect.
Code: SELECT firstJOIN.trainID, firstJOIN.trainName, firstJOIN.stationID, firstJOIN.stationName, firstJOIN.distance_miles, firstJOIN.time_mins FROM (trains INNER JOIN ((station INNER JOIN lineStation ON station.stationID = lineStation.stationID) INNER JOIN bookingLeg ON bookingLeg.startID = station.stationID or bookingLeg.endID = station.stationID ) ON trains.trainID = bookingLeg.tid) as firstJOIN
Can Access do something similar to this, in the FROM statement I joined 4 tables, because each unique fields are in each table and I have to joined them to get those fields. I called this join firstJOIN and in the SELECT statement, I list those columns in the table by calling it firstJOIN.trainID. Can Access do something like this, but syntax it differently?
I am trying to loop through a table and count the duplicate records only once. Please see the attached file.
1) In the test table, I want to loop through all pt_accts.
2) In the countable column, if an acct repeats, I essentially just want to put "1" in one of the records. For the non-repeating accts, putting in a 1 is sufficient. Basically, I just don't want to count the duplicate ones multiple times.
In the example, acct "aaa" repeats, but there is just one "1" in the countable column. "eee" repeats as well, but there is just one "1" and the rest is 0.
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)