473,396 Members | 1,971 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,396 software developers and data experts.

One line of code in Loop gives undesirable results

The code below copies the values of the selected record to all records on my form.

But, this line in the code is giving me undesirable results
Expand|Select|Wrap|Line Numbers
  1. .Fields("ResultsID").Value = Me.TestResultID.Value
Instead of copying the TestResultIDs of each record into ResultsID, it makes all ResultsID the same as the selected record's TestResultsID.

Where would be the best place to move that line of code to?
Expand|Select|Wrap|Line Numbers
  1. With Me.RecordsetClone
  2. .MoveFirst
  3. Do While .EOF = False
  4. If .Fields("[Ordered Analyte]").Value = Me.[Ordered Analyte].Value Then
  5. .Edit
  6.     .Fields("DateStarted").Value = Me.DateStarted.Value
  7.     .Fields("TimeStarted").Value = Me.TimeStarted.Value
  8.     .Fields("DateCompleted").Value = Me.DateCompleted.Value
  9.     .Fields("TimeCompleted").Value = Me.TimeCompleted.Value
  10.     .Fields("Result").Value = Me.Result.Value
  11.     .Fields("Count").Value = Me.[txtCount].Value
  12.     .Fields("ResultsID").Value = Me.TestResultID.Value
  13. .Update
  14. End If
  15. .MoveNext
  16. Loop
  17. End With
May 11 '17 #1
4 871
jforbes
1,107 Expert 1GB
In your code:
Expand|Select|Wrap|Line Numbers
  1. .Fields("ResultsID").Value
refers to the Current Record that the RecordsetClone is on.
Expand|Select|Wrap|Line Numbers
  1. Me.TestResultID.Value
refers to the Current Record of the UI. So, the code
Expand|Select|Wrap|Line Numbers
  1. .Fields("ResultsID").Value = Me.TestResultID.Value
is doing exactly what you asking of it. My guess is you should really leave this field alone as it probably already has the correct value, or you want this:
Expand|Select|Wrap|Line Numbers
  1. .Fields("ResultsID").Value = .Fields("TestResultID").Value
May 11 '17 #2
NeoPa
32,556 Expert Mod 16PB
As J says, it's hard to understand why you might expect anything other than what you're getting.

Unfortunately your description doesn't paint much of the story so we could only guess at this point. For instance, there's no description of the form or how it's structured.
May 11 '17 #3
The form is a continuous form. It typically has 25 - 30 records and is partially populated when the record is created. The rest of the fields are populated at different time and all records at once. The fields being populated are typically the same values.
The code will allow me to enter data into the first record and the fire the code via a command button to populate all the records on the form with the same values.
ResultsID is a field that links each record to a master table with TestResultsID being the primary key. The issue with my code is that when the ResultsID fields are the same for all records on the form, I lose the one to one relationship with the master table.
WHat I need to happen is DAteStarted, TimeStartedDateCompleted, TimeCOmpleted, Result,and Count need to be the same for all records on the form. ResultsID and TestResultID need to be the same for each individual record which created the link to the master table
May 12 '17 #4
NeoPa
32,556 Expert Mod 16PB
DetrieZ:
The form is a continuous form. It typically has 25 - 30 records and is partially populated when the record is created. The rest of the fields are populated at different time and all records at once. The fields being populated are typically the same values.
This explanation is hard to follow. You say the record in one place and the next you refer to all records. What you actually mean is obscured.

My best guess though, is that you want the fields you mentioned to be populated across some grouping or other that is reflected in the form.

What you say about [ResultsID] & [TestResultID] are too confusing to follow without any context, and you give none. Nor any example data that would help us guess what you don't tell us.

As I tried to explain before, your explanation of the situation you're dealing with is critical to our being able to help. A two minute attempt at putting your ideas into words will maybe get you a five minute explanation of why that isn't enough, but unless you do a proper job of explaining what you're working with and what you actually require then we won't get very far.

I don't know if this is a hobby for you or if it's work-related. Both are perfectly acceptable. Work as if it's business related though. Work as if your boss will be reading what you're saying. Impress them. You won't regret it.
May 13 '17 #5

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

Similar topics

2
by: Trevor | last post by:
I have created a class Newsgroup which allows itself to be serialized using Xml serialization attributes. public class Newsgroup { public string Name;
6
by: Joe Piscapo | last post by:
Hello, When I compile my program in Visual Studio it does not work for every input, some numbers make it crash. But compiling in gcc works for those numbers that made it crash in Visual Studio. ...
2
by: Fred Armitage | last post by:
I have a fairly complex application written using a vb code-behind dll. However, I'd like to write one particular aspx page utilising in-line code so that it can easily be modified as needed by the...
1
by: redhair | last post by:
In a asp.net page (.aspx) below, I'd like to know the in-line code ("<%Output()%> ) will be executed in which page process lifecycle? thanks. <Script Language="VB" Runat="Server"> Sub...
0
by: phil-news-nospam | last post by:
I was experimenting with buttons in HTML/CSS and encountered some strange behaviour when changing the padding property setting in the stylesheet. Maybe it's not a stylesheet issue, but since that's...
0
by: Jon Paal | last post by:
what would be the command line code to add an image as a resource to a dll ?
4
by: Pietro Cerutti | last post by:
Hi group, #include <stdio.h> #include <unistd.h> #include <time.h> int main(void) { time_t t1, t2; char *st1, *st2;
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
1
by: rahullko05 | last post by:
one line code to replace an image without page refresh
1
by: rahullko05 | last post by:
Can anybody help me? to write one line code to render html inside a div element. Thanks.
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.