473,768 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pasting multiple records in a form After Update

121 New Member
Hi,

i have a form that runs a query in a recordset on the after update method if i copy and paste one record at a time the query picks up the records in the underlying table but if i paste multiple records the query fails to pick up the set of pasted records i think the after update method is running before the table is properly updated when i paste a group of records I have also tried running the code from the after insert method with no luck

Any help is much appreciated

Regards Phill


Expand|Select|Wrap|Line Numbers
  1. Dim dbsCurrent As Database
  2.     Dim dbsLinkedData As Database
  3.     Dim rstQAssignedHrsSum As DAO.Recordset
  4.     Dim rstTblAssignHrs As DAO.Recordset
  5.     Dim QueryProjID As Integer
  6.     Dim QuerySessionID As Integer
  7.     Dim TableProjID As Integer
  8.     Dim TableSessionID As Integer
  9.     Dim TotalHrsSum As Integer
  10.  
  11. 'sets quer recordset and the the table where the data is going to be written
  12.  
  13.     Set dbsCurrent = CurrentDb
  14.     Set dbsLinkedData = DBEngine.OpenDatabase("C:\Database\ClientBooking\ClientData03")
  15.  
  16.     Set rstTblAssignHrs = _
  17.         dbsLinkedData.OpenRecordset("T_AssignHours", dbOpenTable)
  18.     Set rstQAssignedHrsSum = _
  19.       dbsCurrent.OpenRecordset("Q_SFormTotalHrs", dbOpenDynaset)
  20.  
  21.  
  22.   Do While Not rstTblAssignHrs.EOF
  23.  
  24.  
  25.         TableProjID = rstTblAssignHrs!ProjectID
  26.         TableSessionID = rstTblAssignHrs!SessTypeID
  27.  
  28. 'sets completed hours to zero
  29.  
  30.         rstTblAssignHrs.Edit
  31.         rstTblAssignHrs!CompletedHrs = 0
  32.         rstTblAssignHrs.Update
  33.  
  34.  
  35.   Do While Not rstQAssignedHrsSum.EOF
  36.  
  37.         QueryProjID = rstQAssignedHrsSum!ProjID
  38.         QuerySessionID = rstQAssignedHrsSum!SessTypeID
  39.         TotalHrsSum = rstQAssignedHrsSum!sumofexpr1
  40.  
  41.         rstQAssignedHrsSum.MoveNext
  42.  
  43. 'edits total hours
  44.  
  45.  If TableProjID = QueryProjID And TableSessionID = QuerySessionID Then
  46.  
  47.         rstTblAssignHrs.Edit
  48.         rstTblAssignHrs!CompletedHrs = TotalHrsSum
  49.         rstTblAssignHrs.Update
  50.  
  51.  
  52.  ''This sets reports sent to false becuse assigned hours has been edited
  53.  
  54.     If rstTblAssignHrs!CompletedHrs <= rstTblAssignHrs!AssignHours * 60 / 100 * 75 Then
  55.  
  56.         rstTblAssignHrs.Edit
  57.         rstTblAssignHrs!ReportSent = False
  58.         rstTblAssignHrs.Update
  59.  
  60.     End If
  61.  
  62.  
  63.  End If
  64.  
  65.  
  66.     Loop
  67.  
  68.         rstTblAssignHrs.MoveNext
  69.         rstQAssignedHrsSum.MoveFirst
  70.  
  71.     Loop
  72.  
  73.  
  74.  
  75. rstTblAssignHrs.Close
Mar 9 '09 #1
4 5291
phill86
121 New Member
Hi,

I think this problem occurs because when pasting multiple records the table is in "Pre-update" mode untill you click off the new pasted records i have tried to refresh and requery and on dirty set to false but none of this works is there any way i can force the records to be written to the table before i run the after update code?

Please help this is driving me nuts!!!

Regards Phill
Mar 10 '09 #2
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Sorry Phill, but what you are doing is as unclear as your question, unusually in your case.

You mention 'pasting' records - what has this got to do with the code you have shown? The code is looping through two recordsets in what appears to be another database on drive C, editing individual fields and updating values as you go. I can't see what this has to do with pasting anything.

If you could give a more coherent view of what you are really trying to do it would help us to help you more easily.

I would strongly advise against making assumptions about what is going on regarding update events. Unless you have traced the event sequences for yourself such assumptions can be seriously misleading and send you and us on entirely the wrong path, especially when the logic of what you are trying to achieve is not obvious...

Please be aware that form record events such as the before and after update ones are not normally triggered by copying and pasting records into a table, just as they are not triggered if you modify a field using VBA code; the events concerned are triggered when users modify fields in the underlying dataset manually. If you are, say, manually amending a record and you then Paste Append some other records the current record will be saved by Access first, triggering its Before and After Update events, but not for the pasted records at all...

It is safer and simpler to assume until proven otherwise that there is an underlying logic error in what you are trying to achieve, or your code, or both.

-Stewart
Mar 12 '09 #3
missinglinq
3,532 Recognized Expert Specialist
I'm still trying to figure out the "after update method!" Adding/editing any data in the Form_AfterUpdat e always causes a major coding burp, because changing data triggers the Form_BeforeUpda te event, which in turn triggers the Form_AfterUpdat e event, which in turn triggers the Form_BeforeUpda te, and so on and so forth! In other words, you create an endless loop!

Linq ;0)>
Mar 13 '09 #4
phill86
121 New Member
Hi,

Thanks for the reply sorry i didnt make the question clearer

I have a form with two sub forms. The sub forms are embedded in a tab control the first sub form contains records that are related to training sessions in these records it contains start and end dates and times and the duration of the sessions is worked out from the start and end times

so for example...

Project 1 task 2 start 1/1/09 09:00 - 1/1/09 12:00 3hr duration

The secound sub form contains task asignment details for example

Project1 task 1 Assigned hrs 10 completed hours 5
Project1 task 2 Assigned hrs 5 completed hours 3

so basically the code that i posted works out how many hours have been completed for the assigned tasks in form 2 in the sessions from form 1

so for example project 1 task 2 could have several record entries where the hours sum up to 10 completed hours

the code then rights these summed hours to a sperate table Assigned hours which is on sub form 2

This all works fine when i copy and paste a single record in sub form 1 but if i copy and paste several records in sub form 1 it will not update the completed hours in sub form 2 this is because the query i am using in the recordset runs before the records are "properly written" to the table...

I have since discovered a work around instead of using a tab control i use a button for each form and set the visible property for each of the forms to false until the relative button is pressed which turns the visible property to true this has the effect of taking the focus of the pasted records on form 1 which means the records get "properly written" and the query is able to pick up the data from the newly pasted records.

I hope my ramblings now make sense and altough i do have a work around it would be nice to know why this happens because i have come across this problem before with little success

Thanks for your time much appreciated

Phill
Mar 13 '09 #5

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

Similar topics

5
5213
by: R Duncan | last post by:
Hi, I'm considering moving a payroll application out of Microsoft Access to some web-based solution. It is getting way to big for Access and the system is growing unstable, so I'm learning PHP and MySQL and things are looking very promising. There is one piece of this I am having problems with. The attendance module shows users all their employees in a table and allows them edit it this way. My users need to be able to see and update...
1
2214
by: Roy Adams | last post by:
Hello people I've recently been woring with multiple insert from text fields and got that woking fine thanks to the help from people from this forum now i'm trying to deal with multiple update, I'm pretty much using the same script but it isn't working properly I have a text field in a form with a text field called color, in a repeated region, that shows the amount of colours for the item that your viewing it submits to another page that...
0
2407
by: Chris Hall | last post by:
The records in my database are displayed in a form as follows: %> <form action="report-ammend1.42.asp" method="post"name="form"> <table border=1> <% x = 1
7
4099
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
2
4721
by: Jeremy | last post by:
I have a pretty straightforward database that is designed to record free-form information about products (date, source and a memo field). This is searched and updated via a form. For new records, the memo field is usually filled by cutting and pasting from e-mails, web content and spreadsheets. The only problem is that some of the memos can be just a few words, and some can be tens or hundreds of lines, and I've realised that zooming...
3
2305
by: Mike | last post by:
Using MS Access XP standard install (no Jet or MDAC updates applied yet) as front end, MySQL 4.0 as backend and MySQL ODBC connector version 3.51. When pasting multiple records into the database either in a form or directly in the table, all records / fields display #deleted in each column. This only happens when pasting multiple records, if a single record is pasted, the #deleted comment does not appear. When I refreash the view, the...
5
13994
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two button "copy" and "paste". Works like magic. My problem is how can I copy multiple records and paste them at the same time. My data entry form has main form that has a Questionlist box of Questions. The second list box on the same form displays...
7
15658
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
2
2367
by: phill86 | last post by:
Hi, i have a recordset that updates a table which works fine when you add, update and paste a single record but if you try and paste multiple records it will only update the table with the prevoius records and it will ignore the new pasted records i am running the following code on the afterupdate event in the form Please Help Dim dbsCurrent As Database Dim dbsLinkedData As Database
0
9575
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10015
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.