By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,863 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,863 IT Pros & Developers. It's quick & easy.

One line of code in Loop gives undesirable results

P: 6
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
Share this Question
Share on Google+
4 Replies


jforbes
Expert 100+
P: 1,107
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
Expert Mod 15k+
P: 31,418
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

P: 6
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
Expert Mod 15k+
P: 31,418
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

Post your reply

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