473,378 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to edit and update recordset

547 512MB
I use the following code to append individual records from the "Fis_CaptureT" table, to the "Fis_CaptDataT" in realtime per row. It works 100%, until i correct an error in the "OrderQty" field, in the "Fis_CaptureT" table.

Expand|Select|Wrap|Line Numbers
  1.    Dim MyDB As DAO.Database
  2.    Dim rstEntry As DAO.Recordset
  3.       Set MyDB = CurrentDb
  4.        Set rstEntry =  MyDB.OpenRecordset("Fis_CaptDataT", dbOpenDynaset, dbAppendOnly)
  5.   With rstEntry
  6.   .AddNew
  7.   ![Client_lookup] = Me![Client_lookup]
  8.   ![Item_Lookup] = Me![Item_Lookup]
  9.   ![CPrice] = Me![Price]
  10.   ![Order_No] = Me![Order_No]
  11.   ![OrderDate] = Me![OrderDate]
  12.   ![OrderQty] = Me![OrderQty]
  13.   ![InvoiceQty] = Me![InvoiceQty]
  14.   .Fields("Transaction" & CStr(Me![Transaction])) =    Me![InvoiceQty]
  15.   ![Fis_CaptID] = Me![Fis_CaptID]
  16.     .update
  17.     End With
  18.    rstEntry.close
  19.    Set rstEntry = Nothing
My question - how can i change the "OrderQty" in the
main capturing table - " Fis_CaptureT" and then it updates this same record in realtime in the 2nd table - "Fis_CaptDataT", without creating another record when changing it.


mainform = OrderingF
subform = Fis_OrderICNSF
field = OrderQty in both tables
main table = Fis_CaptureT
2nd table = Fis_CaptDataT
[Fis_CaptID] appears in both tables, and is set for "no duplicates allowed" in both

I imagine it has to do with edit+update in the recordset. But how do i adjust the above code to incorporate this?


Currently i get around this by using the following code
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Fis_OrderEditF", acNormal, "", "[Fis_CaptID]=" & "" & Fis_CaptID & "", , acNormal
  2. [Forms]![Fis_OrderEditF]![OrderQty] = [Forms]![OrderingF]![Fis_OrderICNSF]![OrderQty]
  3. [Forms]![Fis_OrderEditF]![InvoiceQty] = [Forms]!
  4. [Forms]![Fis_OrderEditF].Requery
  5. DoCmd.close acForm, "Fis_OrderEditF"
The code is situated in the "error trapping" part of the main recordset append code at the bottom, and if a duplicate of the same ID gets appended due to a change in the "OrderQty" and it getting appended, it kicks in.
I open a 2nd form in the background containing the Fis_CaptDataT table, update the specific field using the afterupdate function and closing it again immediately. Is there a better way using recordsets?

Please help. I have struggling for 2 days non-stop now.
Oct 23 '11 #1

✓ answered by ADezii

If I am interpreting your Request correctly, you must first see if the Data has been Captured. It it hasn't been Captured, it is an AddNew operation, if it was Captured, it is an Edit operation:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim strSQL As String
  4.  
  5. Set MyDB = CurrentDb
  6. strSQL = "SELECT * FROM Fis_CaptDataT WHERE [Fis_CaptID] = " & Me![Fis_CaptID]
  7.  
  8. 'See if the Data has already been Captured, if not, Add, not Edit the Record
  9. If DCount("*", "Fis_CaptDataT", "[Fis_CaptID] = " & Me![Fis_CaptID]) = 0 Then     'NOT Captured/ADD
  10.   Set rst = MyDB.OpenRecordset("Fis_CaptDataT", dbOpenDynaset, dbAppendOnly)
  11.     With rst
  12.       .AddNew
  13.         ![Client_lookup] = Me![Client_lookup]
  14.         ![Item_Lookup] = Me![Item_Lookup]
  15.         ![CPrice] = Me![Price]
  16.         ![Order_No] = Me![Order_No]
  17.         ![OrderDate] = Me![OrderDate]
  18.         ![OrderQty] = Me![OrderQty]
  19.         ![InvoiceQty] = Me![InvoiceQty]
  20.         .Fields("Transaction" & CStr(Me![Transaction])) = Me![InvoiceQty]
  21.         ![Fis_CaptID] = Me![Fis_CaptID]
  22.       .Update
  23.   End With
  24. Else        'Data Captured, so Edit the Recordset
  25.   Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  26.     With rst
  27.       .Edit
  28.         ![Client_lookup] = Me![Client_lookup]
  29.         ![Item_Lookup] = Me![Item_Lookup]
  30.         ![CPrice] = Me![Price]
  31.         ![Order_No] = Me![Order_No]
  32.         ![OrderDate] = Me![OrderDate]
  33.         ![OrderQty] = Me![OrderQty]
  34.         ![InvoiceQty] = Me![InvoiceQty]
  35.         .Fields("Transaction" & CStr(Me![Transaction])) = Me![InvoiceQty]
  36.         ![Fis_CaptID] = Me![Fis_CaptID]
  37.       .Update
  38.     End With
  39. End If
  40.  
  41. rst.Close
  42. Set rst = Nothing

4 20818
ADezii
8,834 Expert 8TB
If I am interpreting your Request correctly, you must first see if the Data has been Captured. It it hasn't been Captured, it is an AddNew operation, if it was Captured, it is an Edit operation:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim strSQL As String
  4.  
  5. Set MyDB = CurrentDb
  6. strSQL = "SELECT * FROM Fis_CaptDataT WHERE [Fis_CaptID] = " & Me![Fis_CaptID]
  7.  
  8. 'See if the Data has already been Captured, if not, Add, not Edit the Record
  9. If DCount("*", "Fis_CaptDataT", "[Fis_CaptID] = " & Me![Fis_CaptID]) = 0 Then     'NOT Captured/ADD
  10.   Set rst = MyDB.OpenRecordset("Fis_CaptDataT", dbOpenDynaset, dbAppendOnly)
  11.     With rst
  12.       .AddNew
  13.         ![Client_lookup] = Me![Client_lookup]
  14.         ![Item_Lookup] = Me![Item_Lookup]
  15.         ![CPrice] = Me![Price]
  16.         ![Order_No] = Me![Order_No]
  17.         ![OrderDate] = Me![OrderDate]
  18.         ![OrderQty] = Me![OrderQty]
  19.         ![InvoiceQty] = Me![InvoiceQty]
  20.         .Fields("Transaction" & CStr(Me![Transaction])) = Me![InvoiceQty]
  21.         ![Fis_CaptID] = Me![Fis_CaptID]
  22.       .Update
  23.   End With
  24. Else        'Data Captured, so Edit the Recordset
  25.   Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  26.     With rst
  27.       .Edit
  28.         ![Client_lookup] = Me![Client_lookup]
  29.         ![Item_Lookup] = Me![Item_Lookup]
  30.         ![CPrice] = Me![Price]
  31.         ![Order_No] = Me![Order_No]
  32.         ![OrderDate] = Me![OrderDate]
  33.         ![OrderQty] = Me![OrderQty]
  34.         ![InvoiceQty] = Me![InvoiceQty]
  35.         .Fields("Transaction" & CStr(Me![Transaction])) = Me![InvoiceQty]
  36.         ![Fis_CaptID] = Me![Fis_CaptID]
  37.       .Update
  38.     End With
  39. End If
  40.  
  41. rst.Close
  42. Set rst = Nothing
Oct 23 '11 #2
neelsfer
547 512MB
Thx Mr Adezi. I will incorporate it. I think you have it right.

I may start to capture data and on completion of that specific row, I may notice an error. I then need to go back to the row with the error, change the quantity and it is updated to the 2nd table.
Oct 23 '11 #3
neelsfer
547 512MB
Working 100%. thx a million Adezi. Taken me months to get this right. I can now also use this in my timing program
Oct 23 '11 #4
ADezii
8,834 Expert 8TB
Glad it all worked out for you...
Oct 23 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Jim | last post by:
Hi, Let me explain how I'd generally do things. For a page where the user edits data, I'd generally call it something like editfred.php (for example), the page which updates the data would be...
0
by: Tom | last post by:
I created a c# web form. I added a DataGrid1 to it. I added the Edit, Update, Cancel Button Column. I added two Bound columns. All is well. But when I run the app and press the edit...
0
by: Andreas Klemt | last post by:
Hello, how can I easily solve the nested DataGrid problem working correctly with edit / update events? Is there any very simple example? Who has the same problems? Thanks in advance, Andreas
3
by: Hartmut Schroth | last post by:
Hi, I need a solution for the following problem: In the item template of a datalist control I have already a button control with the commandname set to "select" to perform some specific...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
0
by: jinhy82 | last post by:
Hello! I am using DataGrid to display details from Ms Access. Fe features such as Edit, Update and Delete are added, but they did no function. Can anyone help me? Thank you very much!!! For the...
3
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
0
by: anwarulhuq | last post by:
I have placed Edit-Update-Cancel Link button from Properties builder of the Data Grid. Its working but the problem what im facing is.. It doesnt work till i click for two times. Link button should...
4
by: yehey2010 | last post by:
Hi, I have problem with my ASP.Net Code, I used GridView with Edit/Update on it. However the program seems not work correctly because it doesn't Update the OLD VALUE with the NEW VALUE. Please...
1
by: pieandpeas | last post by:
Hi, i've been searching the internet for a good reference of how to add the update column functionality to a gridview, coding everything in the .vb behind the page stuff myself, e.g not using a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.