Modules & VBA :: Way Of Looping Through Continuous Form Recordset And Running Update On Each Line?
Jun 11, 2014
i have set up an update query. is there a way of looping through a continuous form record set and running the update on each line?
View Replies
ADVERTISEMENT
Jun 18, 2014
Im still struggling with working with recordsets.What i want to achieve is to loop through a continuous form recordset, Using the OrderDetailFK from the record set and the OrderDetailPK in the OrderDetail Table
Looking at the Status FK in the OrderDetail Table. IF the OrderDetail Status = 2 then i want to make the textbox enable property = False. I have made the bellow SQL string which is placing all the criteria i just need to link it into a recordset?
Code:
mySQL = "SELECT [StatusFK] FROM [tblOrderDetail] WHERE [OrderDetailPK] = " & rst!OrderDetailFK & " AND [StatusFK] = 2 "";"""
View 4 Replies
View Related
Jul 8, 2014
I have learned the basic looping technique for going through a record set from the following link. I need to know if my logic is on the right track. URL...
My question is a followup to a thread that was opened on this forum: URL....I want to do the following:
1) Use record set looping technique to fix a variety of incorrect naming conventions to a standard format
2) Update the table (or create a new table) from the updated record set values. (Is my logic going to update the table selected in the code I used to dimension the record set or will I need to do something else to make the changes available for other tasks after record set is closed ? After the naming conventions are fixed this data will be available for excel automation that I am working on and posting questions on another thread in this forum. HAHA I'm going code BANANAS)
3) rs.fields![fleetlocation] is used so many times, how can I make this a variable (what do I dimension the variable as?)
4) Use an AND statment with an if statment (how to do this with correct syntax)
Code:
sub loopandfix()
on error goto errorhandler:
strSQL = "tblUnionQueryResults" 'table was created from a union query but has inconsistant naming conventions for the fleet location name
[code]....
View 9 Replies
View Related
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
Aug 6, 2015
I follow a ritual of moving last to first before looping through a recordset. I started following this because in the way back (I think on office 2003). I used to get an error if don't do it. Is the problem still exists? Is this ritual scientific still?
Code:
Sub mac()
Dim myRset As Recordset2
Dim AttachmentField As Field2
Set myRset = CurrentDb.OpenRecordset("Table1")
With myRset
.MoveLast
[Code] ....
View 2 Replies
View Related
Nov 28, 2013
I'm trying to populate a listbox from a recordset. I will explain what I'm trying to achieve.
I have a (continuous) form with some data from a table. On the form header I have a listbox, showing all (distinct) customers from that form.
The user is able to do some filtering. That all works great. But I want to populate the listbox with ONLY the customers on the form AFTER filtering.
One way I thought might me the solution was using RecordClone. But I'm stuck there. It must be something simple for an expert. I'm not entirely a newbie, at least not to VBA. Is there an easy way to refer the listbox' recordset to the actual recordset on the form?
View 1 Replies
View Related
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
May 29, 2015
I have a bound continuous tabular form,However, based on data content in one field of a record, I want a checkbox in the same record enabled, so the user can check it if necessary. I have created a record set using the form as shown below, and I am looping through each record. To show that my code is referring to the field with required data content, I display it as a message box and it works, yet my checkbox does not enable.
I have the code in the form_load event, however, for testing purposes I have it behind a button.If I am seeing this properly, the code behind the button enables the checkbox for ALL records once the criteria in the required field is true, and based on the last record, which has no data content, it disables the checkbox in ALL records. I also have the PK ID for each record hidden in the form. Can I utilize that to target the checkbox of each individual record??
Form Detail
-Form does not allow additions or deletions. Edits allowed
-All fields are disabled and locked
-I only want the check box to unlock if data is found in the "RequiredField" as referred to below. I have also tried if not isNull(requiredfield.value) then -enable checkbox, which yields the same results
Here is my code
Code:
Dim rstMyForm As DAO.Recordset
Set rstMyForm = Forms!MyForm.Form.Recordset
rstMyForm.MoveFirst
Do While Not rstMyForm.EOF
If Not RequiredField.Value = "" Then
[code]...
View 14 Replies
View Related
Apr 27, 2006
Greetings
I am using the code below to try to update some tables and data. My problem is the code seem to only work on one line in the recordset the last line. I have put up to 10 records in the recordset and it still only does the last record.
Any help would be great as it is the last bit of the project and I am behind my deadline;
'============================
'Public Procedures
Public Sub UpdateQuestion()
Dim UpdateAnswer As Byte
Dim db1 As DAO.Database
Dim rst, R As DAO.Recordset
Dim volval As String
Dim rcount As String
UpdateAnswer = MsgBox("Is this " & _
"work note ready to update and complete Press" & vbCrLf & _
"YES to update and complete OR " & vbCrLf & "NO just " & _
"to update and close", vbQuestion + vbYesNo + _
vbDefaultButton1, "Update and Complete")
If UpdateAnswer = vbYes Then ' (Default)
If Forms![frm_Data_JobOrder_Note]![FrmDestination].Form![StatusTransfer].Value = -1 Then 'do nothing
Else
Set db1 = CurrentDb
Set R = Me.Form.RecordsetClone 'create a recordset of the data
R.MoveFirst 'got to start somewhere
Do Until R.EOF ' start loop
Set rst = db1.OpenRecordset("tbl_Data_Vessels")
rst.Index = "PrimaryKey"
rst.Seek "=", Forms![frm_Data_JobOrder_Note]![FrmDestination].Form![VesselID]
rst.Edit
volval = rst![Volume]
rst![Volume] = Forms![frm_Data_JobOrder_Note]![FrmDestination].Form![FinalVolume]
If rst![Volume] < 0 Then
MsgBox ("Problem restoring original value"), vbCritical, gstrAppTitle
rst![Volume] = volval
rst.Update
rst.Close
Exit Sub
End If
rst![Status] = Forms![frm_Data_JobOrder_Note]![FrmDestination].Form![Status]
rst![Updated] = [Forms]![frm_Data_JobOrder_Note]![EnterDate]
rst![LastOp] = [Forms]![frm_Data_JobOrder_Note]![JobNumber]
rst![ContentsOwner] = Forms![frm_Data_JobOrder_Note]![CompanyID]
rst.Update
rst.Close
R.MoveNext
Loop
Set db1 = Nothing
Set rst = Nothing
End Sub
Thanks
rbinder
View 1 Replies
View Related
Nov 30, 2006
How do I make running numbers in a continuous form and independent from record ID, each time starting from 1, 2, 3 and so on?
:confused:
View 4 Replies
View Related
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
Jan 26, 2015
i want to be able to create an On Click Event when pushing a command button that will run an Update query to update a record and after it has been updated that specific record will pop up on a Form and be displayed. i know a different way is to run the Update query and then have it displayed in a Select query but i want it to be displayed on a Form instead. is it possible?
View 4 Replies
View Related
Jan 20, 2015
I have inherited an old database with a new field to add some new invoice numbers and increment the number to each recordset by + 1. Starting at 001. I have formatted the field to a Number Field and formatted it to 000"/2015". I now need to populate over 2000 records with the sequential numbers for each record.
I have created the following code as my attempt. Of course it doesn't work!
Code:
Sub AddNumbertoRecords()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim counter As Long
counter = 1
Set db = CurrentDb()
[Code] ....
View 7 Replies
View Related
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
Oct 13, 2014
I have a form in my front end database that is supposed to allow a user to search for a record based on account number and then make changes to the that record and for it to save in the back end database. I have the search function working where it populates different input boxes on the form with what is stored in the back end database but I cannot get the update function to work. I have tried to assign each input box with a variable and then run an Update SQL function to update each of the fields but the updates are not storing. Any example of a successful update statement that uses VBA variables in it or a way to update a specific record via a recordset type function?
View 8 Replies
View Related
Jun 7, 2013
I am trying to update a recordset using VBA based on the max "process instance" from another table. After the code executes, the field I am updating is still blank.
Code:
Set rs = db.OpenRecordset("myTable", dbOpenDynaset)
If Not (rs.BOF And rs.EOF) Then
rs.MoveFirst
Do Until rs.EOF = True
emplid = rs![Employee Number]
[Code] ....
View 5 Replies
View Related
Nov 29, 2014
I have a module which reads a CSV transaction file line by line and adds the correct transactions to an access table and places the wrong ones in a logfile.Now some transactions are rejected twice there is even one rejected six times. Whereas one wrong transaction is processed only once. I am certainly overlooking something obvious in the logic but what. Here is the relevant code.
Code:
Function ImportCSVForConfederation(inputCSV, ORG)
Dim TNO As Integer, TACT As Integer, TABLE As String, TLINE As String, I As Integer, J As Integer, K As Integer
Dim FLD1 As String, FLD2 As String, FLD3 As String, FLD4 As String, LogFile As String, LogPath As String
Dim Lim As String, ITNO As Integer
[code]....
View 8 Replies
View Related
Mar 2, 2005
Right. I have a textbox say called TextA which is bound to COl A of my table THis table is being shown as continous forms (ie a set of ros in the detail section) and for each row I want to use a VB function to calculate another value from TextA and update the Value attribute of TextB.
I can't for the life of me figure out which event I can use to trigger this function so that EVERY row of the detail section has this function applied to it. I do NOT want to ahve to mouseover or click on etc any fields, I want it all to be calculated when the form has done loading. So far the best I can come up with is OnCurrent, which is no damn use at all - it does the first record and then once loaded the record which has focus.
Please please help - I've got a long night ahead of me and this is due to be finished am tomorrow - argh!
Cheers!!
View 5 Replies
View Related
Nov 18, 2014
I am having a little difficulty with my importing in Access. Every time I import my text file, the lines will be jumbled. I have been reading up and I found this recordset code that seems to be what I need:
Code:
Dim strLine As String
Dim intLineNum As Integer
Dim MyDB As DAO.Database
Dim rst As DAO.Recordset
Open "C:TestTest.txt" For Input As #1
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("tblResults", dbOpenDynaset)
CurrentDb.Execute "DELETE * FROM tblResults", dbFailOnError 'Clear tblResults
[code]....
Basically, this code will extract data from the text file as long as it fulfills the Mid$ criteria. Here's where my problem comes. Each line in my text file is of different lengths and I have to capture the entire line.
I think using the Left$ function would work, but I don't know how to determine the character count such that the entire line of text would be inserted into the table.
Another difference between what I need and the code above is that, I am required to store each line into each row of my table, meaning
Line 1 is placed in Row 1 Column 1
Line 2 is placed in Row 2 Column 1
Line 3 is placed in Row 3 Column 1
.
.
.
Line X is placed in Row X Column 1.
View 14 Replies
View Related
Feb 20, 2006
Hi,
I want to show some text from another table based on the values of the bound fields in each record of a continuous form. I thought it would be easy, but I can't get it to work.
I step through the records in the bound recordset and use some of the values to query another table. Then I use the value from the query to populate the unbound text field.
It works fine for each record. But every time the unbound field is updated, all the records in the continuous form are updated.
I'm stuck on this one. It's probably something simple to fix - if you know what to do!
Do you have any suggestions?
Thanks!
-Daniel
View 10 Replies
View Related
Jun 16, 2014
I have a database and one of the functions is to track the purchase of fuel. Part of purchasing fuel is registering what the current odometer reads. My query gets the Vehicle ID, Date of Transaction and Odometer reading. I want to show a report that shows how many miles the vehicle is has traveled for a certain amount of time. If it's for 2013 then I'll put the criteria for 2014 in the date. This will give me a list of all vehicles and their odometer readings. I then sort the date by ascending.
In the report I group on vehicle ID and then I want to show all their transactions and add up how many miles were driven.
Vehicle 1
1/2/201
1/5/2013
1/15/2013
ETC...
Total Miles Driven in 2014: XXXXXX
View 1 Replies
View Related
Jun 5, 2014
I have a main form with 3 sub forms. The main form is tied to a table called QUOTES_MASTER. The first sub form is tied to a table called QUOTE_ LINE_ ITEMS_DIRTGLUE. It calculates the subtotal when selecting items. The relationship is one-to-many linked on QUOTE_ID.
The second sub form adds up total of all line items and is not tied to a table.The third sub form adds ESTIMATED FREIGHT to the PRODUCT TOTAL and is not tied to a table. how to get the values from the line items form inserted into the QUOTE_LINE_ITEMS_DIRTGLUE table as they are added.
I also want to insert the total value from ESTIMATED DELIVERED into the LINE_TOTALS field in the table QUOTES_MASTER.I tried this code on the product total sub form but it doesn't do anything and there are no errors:
Private Sub PROD_SUB_AfterUpdate()
DoCmd.RunSQL "UPDATE QUOTE_LINE_ITEMS_DIRTGLUE SET QUOTE_LINE_ITEMS_DIRTGLUE.SUBTOTAL = Me.PROD_SUB WHERE QUOTES_MASTER.QUOTE_ID = " & Me.QUOTE_ID
View 6 Replies
View Related
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
Sep 15, 2013
I have the following example of code I have previously used which loops through columns where a column is called "Page1", "Page2", Etc.This is fine when the number of columns is fairly small. But in a new case I have 585 250 columns which may or may not contain some data which is the key.If data exists in column do something and after that or of not move to the next column and do the same thing until there are no more columns?
Code:
Dim rst As DAO.Recordset ' recordset for category data
' open the recordset for categories
Set rst = CurrentDb.QueryDefs!QryRMA.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
[code]...
View 5 Replies
View Related
Jan 31, 2014
I have 2 forms and a macro in Form1 which runs throught every record to update the records, however.I would like to run this macro from the main form (Form2)
I have tried
docmd.openform "Form1"
Run Macro
but it doesnt work
View 4 Replies
View Related
Aug 11, 2015
I have a database that I've split and have deployed to 7 persons.
The thing is, I have three (3) forms:
Form 1
Form 2
Form 3
...that require changing a portion of a line in each form's respective VBA codes. I need to change the directories to where an excel workbook is stored after exporting, and another is where same excel is moved to after being uploaded.
At the moment, during deployment I have to manually change the directories.
I was thinking of maybe a pop-up form with four (4) fields that allows the user to select his/her name at the start-up of their frontend app, and paste the directories in the other text boxes provided.
This information will then be used to replace the directories in the VBA.
If I were to make changes and have to redeploy, I would have to do everything manually again.
View 6 Replies
View Related