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 Replies


ADVERTISEMENT

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 :: Loop Through SubForm RecordSet?

Jun 4, 2014

Is there a way of looping through a non update able continuous subform, and using information from each line.

Which creates a new record in another table? so if there are 3 records in the subform it creates 3 new records in the other table and so on?

View 3 Replies View Related

Modules & VBA :: Loop Recordset With IF Greater Than?

Jun 16, 2014

Im trying to create a record set that compares a quantity value in the recordset to a Value in a temporary table that holds the most recent remaining quantity. I have the following code in the after update of a text box, but it does not trigger. I want it to run after a value is entered into the text box. Is the code wrong or the location im putting it incorrect?

Code:
Private Sub txtQty_AfterUpdate()
Dim rs As DAO.Recordset
DoCmd.OpenQuery "qryQuantitySoFar"
Set rs = Forms!frmReceive!sfrmReceiveDetailEntry.Form.RecordsetClone

[Code] ....

View 11 Replies View Related

Modules & VBA :: Loop Through A Recordset And Send Appointments

Aug 2, 2013

I have this code (below) that loops through a recordset and sends appointments. It executes the queries correctly and sends all appointments in the table, but sends them only to the contacts listed in the first record of the query. How do I get it to loop the contact details?

Code:
Private Sub SchedFollowUp()
Dim rsFollow As DAO.Recordset
Set rsFollow = CurrentDb.OpenRecordset("SELECT * FROM Follow_Up WHERE HR_Approved = True AND Added_to_Outlook = False AND Cancelled = False;", dbOpenDynaset)
Dim rsEmployee As DAO.Recordset

[Code] ....

View 10 Replies View Related

Modules & VBA :: Recordset Loop Stuck On First Record

May 8, 2014

I am attempting to use 2 fields from a query to supply the Top and Left Properties of a Collection of Rectangle Controls on my form. The purpose of this is to display the locations on a map of "Spots" in a haunted house. The query that I am using shows the spots that have been pre-tagged with the location of where they belong on the map (currently the query has only 24 tagged spots). On the actual form I have rectangle controls (control type acRectangle) with their visible property set to False by default, named box1 through box25 (there will be more eventually, as I am just working with this test group).

I started with the following code, yet it stops after (correctly) placing the first spot on the map (please see the attached jpg):

Code:
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
Dim db As DAO.Database
Dim rst As DAO.Recordset

[Code]....

I'm sure I need to have 'Loop' in there somewhere, but I am not sure exactly where to place it, or if another line is also needed.

View 10 Replies View Related

Modules & VBA :: Loop Through Recordset Not Recognizing Next Move?

Aug 27, 2014

So I have a table "zztblArticles." Some fields should go to "tblArticles" and values in Tag_ID should go to a lookup table "tblTag" and a junction table "tblArticles_Tags." I'll explain the code I've written below:

Code:
Private Sub cmdSubmit_Click()

Dim db As Database
Dim strINSERT As String
Dim strVALUES As String
Dim rszztblArticles As DAO.Recordset

[Code] ....

The first loop through works fine, I get the records uploaded to all tables. The second loop through fails at

Code:
intArticleID = DLookup("ID", "tblArticles", "Sourcing_Date = " & !Sourcing_Date)

Because it can't decide which ID value to use. This is because the value has been duplicated in tblArticles after the code acts on the same record again. It has completely failed to move to the next record in the recordset, despite the .MoveNext before the Loop!

View 12 Replies View Related

Modules & VBA :: Continuous Form - Loop Through Recordset

Jul 22, 2014

In my database, I have a continuous form with a Name, a Date and a Yes/No field.

When the form opens, I want to look at the date of every record on the form and show a message box if it is before the current day.

The code I have is this;

Private Sub Form_Load()
With Me.RecordsetClone
While Not .EOF
If Me.Date1 < Date Then
MsgBox "" & Me.Person & ""
End If
If Not .EOF Then .MoveNext
Wend
End With
End Sub

However, it loops just the first record the amount of times there is of records (i.e., it will only show the first person's name in the message box, and will show 3 times if there are 3 records).

View 7 Replies View Related

Modules & VBA :: Recordset Loop Skipping Entry?

Jun 26, 2015

I have 2 identical tables of asset information. Table 1 has 251 records while table 2 has 84 records. All 84 records are in table 1 right now. My end goal is to be able to click a button, have vba script run, and table 2 updates table 1 with any changes from different fields. I know there are merging options with query and what not but the exact structure of my tables doesnt play well with it.

Right now, my code is able to loop through the values of each computername and display it. For some reason, when it gets to the 130th record of table one, the loop skips it and returns the 131st record, it stays one ahead for the rest of the loop and then prints the 130th record finally.

Since I am trying to compare field values, this sudden shift throws everything off. why it skips?

Code:

Option Compare Database
Private Sub UpdateAssetsBTN_Click()
On Error GoTo Err_Proc
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset

[code]....

View 2 Replies View Related

Modules & VBA :: Loop Function Repeating First Line Of Recordset

Aug 17, 2015

managed to get some code up and running but when trying to enhance it I have hit a rut.

I have a function that is looking up a query called Optimisation - Auto Optimise with operational data in it. I only need 2 key fields; consolcode and volume. There are 106 records with different consolcodes each with different volume. e.g consolcode: Chittagong to Rotterdam201452 (Chittagong to Rotterdam by year "2014" by week "52") and volume 161 (cbm)

I then run a code that allocates the volume into specific sea freight containers and returns the values into a different output table.

The allocation code works fine but when I run the loop function for the recordset rsttradelane it runs for the correct amount of records (106) but always returns the first record of Chittagong to Rotterdam201452 and 161 cbm and not the other 105 consolcodes with the different cbm. Giving me an output table with Chittagong to Rotterdam201452 and 161 cbm repeated 105 times!!

Code:
Set rsttradelane = dbsEPIC.OpenRecordset("Optimisation - Auto Optimise")
consollane = rsttradelane!consolcode
ConsolVol = rsttradelane!Volume
Do Until rsttradelane.EOF
'Optimisation code' then
Code:
rsttradelane.MoveNext
Loop
rsttradelane.Close

How do I ensure that each consolcode and its associated cbm is recognised individually and flushed through the optimisation code?

View 3 Replies View Related

Modules & VBA :: Loop To Update Recordset Only Reaches 1st Record

Mar 13, 2014

I found this code and have substituted parameters to suit my own needs however the loop is not working. Only the first record in my recordset (which is a test recordset of only 3 records) is being updated.

Also, for testing only, the edit or update being applied is trivial: Description = "WHITE RESIN". If i can get the loop to work I want to substitute higher functionality to the module.

Private Sub Update_Click()
Dim dbs As DAO.Database
Dim rsQuery As DAO.Recordset

Set dbs = CurrentDb
Set rsQuery = dbs.OpenRecordset("qryRmResin", dbOpenDynaset)

[Code] .....

View 14 Replies View Related

Modules & VBA :: Loop On Recordset - Sending Email Out With All Needed Info

Dec 9, 2014

I have this code here that sends an email out with all the needed info. The problem i ran into was that for my field "item" it is in a table called "test" and there can be more than one record in there. I just can't get it to loop and show me all of the records. Right now it shows me only the first record. Also it is showing the name of the table before the result so i am not sure what is wrong there...

Code:
Private Sub Command4_Click()
On Error GoTo Err_SendInfo_Click
Dim varTo As Variant
Dim varCC As Variant
Dim stSubject As String

[Code] ....

View 4 Replies View Related

General :: Fabricated ADO Recordset - Adding Records

Dec 19, 2013

Example of a fabricated ADO recordset bound to an ADO recordset here: [URL] ..... and it is reattached here.

I have been unable to discover how to add records using the form. So, what needs to be changed, so that one could add records just like with a normal form bound via DAO to a table?

View 14 Replies View Related

Modules & VBA :: Adding Email Address Not In Recordset

Aug 21, 2014

My situation is that , I have a sub for sending an email to a single client on the current form. Using a record set works fine, I now wish to have

.Cc email address which is not part of the Record set ." its to the department head". strEmailAddress = rst![clientEmail] & " ;" & somebody@ntlworld.com

My question is can I type the somebody email address as indicated in red in the above line? to enable the email to go to both addressees . 

set DoCmd.SendObject , , acFormatRTF, clientEmail, _ , , strSubject, strEMailMsg, False, False?

I would prefer to use the Do Cmd SendObject is this is achievable

View 2 Replies View Related

Loop Recordset

Jul 25, 2006

Hi folks,

I have created a recordset and what i want to do is check the field value "SiteRAG" to see if it matches some criteria and if so do some action where the field "SiteID" = the same as a label on a form.

Please see CAPS in middle of code:

Dim db As Object
Dim rs As Object
Dim intCount As Integer, intRecordCount As Integer, intID As Integer
Dim strSQL As String
Dim strRAG As Long
Dim fldItem As Field

strSQL = "SELECT tblSite.SiteID, tblSite.SiteRAG, tblSite.Active " _
& " FROM tblSite " _
& " WHERE (((tblSite.Active)=Yes));"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)


intRecordCount = 0
rs.MoveFirst

CHECK THE FIRST ROW FIELD SiteRAG & IF = TO CRITERIA THEN
DO SOMETHING BASED ON A LABEL MATCHING THE SiteID
ELSE
MOVE TO NEXT ROW

Loop
rs.Close
db.Close


Thanks for any help
Mark

View 2 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 :: 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

Forms :: Recordset Loop Takes Value Only From First Record

Oct 18, 2013

I have a following problem: I have a form in continuous mode. Users are supposed to filter data in it to their liking using inbuild filters in Access. After that there is a button that should calculate total weights in filtered records (at this point, I add more calculations once I have solved this issue). Code of button is as follows:

Code:
Private Sub btnCalculateWeight_Click()

Dim rst As Recordset
Dim weight As Long
Dim material As Long
Dim subtype As Long
Dim locus As Long

[Code] ....

Loop goes through recordset correct amount of times but for unknown reason takes value only from the first record and sums it N times where N is number of records in recordset. Recordset seems to be correctly assigned according to messageboxes I added to pinpoint problem. PotteryWeights is a custom function I made and it works properly.

View 2 Replies View Related

Forms :: Loop Through Continuous Form Recordset Crash

Jun 27, 2014

My application crashes when trying to change the value of a text box in a continuous form. Here is the code:

Code:
Private Sub cboPoCurrency_AfterUpdate()
On Error GoTo ErrHandler
Dim rst As Recordset

[Code].....

If I replace .txtUnitCost by MsgBox .txtUnitCost, it loops correctly through each record and returns the value. But if I try to change the value as shown in above code, MS Access crashes! (This is a desktop application with tables linked to SP lists - not a web app)

[URL]

View 14 Replies View Related

Modules & VBA :: Selecting Records For A Recordset Using Datediff?

Apr 14, 2014

I have a table with Family_Name and Birthdate and tblxx_Familie_ID:

I am trying to create a recordset that selects all records that belong to a certaim Family and where the Person is under 216 months old (under 18)

Set ExternKinder = db.OpenRecordset("Select * from tbl_ExterneGeschwister where tblxx_familie_id=" & Familie!ID & " and " & "Datediff('m',[Geboren_am],[me![Buchungsdatum]) <= 216)

'Buchungsdatum is a filed on a form that I start the procedure from...

View 6 Replies View Related

Modules & VBA :: How To Extract Recordset From Subform Into Recordset Object

Aug 14, 2015

Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.

The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.

The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.

The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.

Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?

Note: Immediate Window - One single field can be returned quickly

There are 48 fields that need validation - is there a way to reference the entire recordset?

Immediate Window during Break Mode:
? me.fsubsrNavSHLBHL("NavSH_QQ")
NESE ' this is the correct value for the current recordsource

Set a breakpoint right after the line:
fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value

Immediate Window:
? me.fsubsrNavSHLBHL.Form.RecordSource
Select * from vsrNavigatorSHLBHL where Well_ID =91229

View 4 Replies View Related

Modules & VBA :: Adding Records To Subform

Sep 9, 2013

I have button the when pressed will insert a record (via an insert into query) to the frmMain and several records to the frmSub.The problem is when a new record is created in the main form the auto number primary key advances. This is fine however the linked Child field which is a foreign key of the main form is not added and the value is blank. I thought this would happen automatically and the Master field would force the child field to be update but this is not happening.Do I have to determine the max number used in the auto number then add 1 to it?

View 7 Replies View Related

Modules & VBA :: Adding All Records From A Subform To Table?

May 26, 2015

I am working with a database that deals with trailers. What is happening is a salesman takes an order for a make and model for a trailer for a customer. The customer can then add some customization to the trailer such as more tail lights or tie down straps. They add the customization on a form called frmCustomQuote. On frmCustomQuote there is a subform called sfQuoteConfigs. On sfQuoteConfigs there is fields such as category and sub catergory that get populated bases on what was selected.

On frmCustomQuote there is a button called "Copy Quote" this will allow the salesman to make an exact copy of the trailer and customization. The quotes are held in a table called tblQuotes and the customization is held in tbQuoteConfigs. Now my problem is when I click on Copy Quote it only copies the first record into tbQuoteConfigs. I can't figure out a way to tell my code to move to the next record within sfQuoteConfigs.

My code:

Code:
Option Compare Database
Option Explicit
'Setup ADODB connection to the tblQuotes
Dim adoQuotesCustomQuote As New ADODB.Recordset
'setup ADODB connection to the tbQuoteConfigs
Dim adoQuoteConfigsCustom As New ADODB.Recordset
'Dim the Variables

[code]....

View 4 Replies View Related

Modules & VBA :: Appending / Adding Certain Records To Another Database

Feb 17, 2015

The goal I am trying to accomplish using VBA within Access 2010 is to append/add certain records to another database (Customer Service) from my database (Client Request). I tried using a macro to append then update records in my database but there is a "lag" time as to when the information is updated in the 'Customer Service' database causing my updates not to occur.

Here is the SQL from my query:

INSERT INTO Issues ( Customer, Title, [Due Date], [Opened By], [Opened Date], Priority, Comments, [Job Number], Description )
SELECT [TBL003_Combined Data].CUSTOMER, [TBL003_Combined Data].TITLE, [TBL003_Combined Data].[DUE DATE], [TBL003_Combined Data].[OPENED BY], [TBL003_Combined Data].[OPENED DATE], [TBL003_Combined Data].PRIORITY,

[Code] ....

And here is how I "thought" I could fix it through Access VBA:

Function UpdateIssuesDatabase()
Dim con As Object
Set con = CreateObject("ADODB.Connection")
On Error GoTo UpdateIssuesDatabase_OpenError
con.Open _

[Code] .....

I have highlighted where it is giving me the issue.

View 9 Replies View Related







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