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

Looping in a Subform

P: 4
The following code is part of a button (on click) that places a check (true) in a filtered subform. The subform is a set of continuous forms. The checks are placed but it gives an error message that it canít go to the next record. When I try to step through it, a check is placed in the first record but errors out before it starts to loop?
Expand|Select|Wrap|Line Numbers
  1. x = Me.Text6
  2. Screen.PreviousControl.SetFocus
  3. DoCmd.GoToRecord , , acFirst
  4.  
  5.     Do While x > 1
  6.     Me.Check48 = True
  7.     DoCmd.GoToRecord , , acNext
  8.     x = x - 1
  9.     Loop
Feb 27 '08 #1
Share this Question
Share on Google+
6 Replies


Expert Mod 2.5K+
P: 2,545
...The checks are placed but it gives an error message that it canít go to the next record. When I try to step through it, a check is placed in the first record but errors out before it starts to loop?

x = Me.Text6
Screen.PreviousControl.SetFocus
DoCmd.GoToRecord , , acFirst

Do While x > 1
Me.Check48 = True
DoCmd.GoToRecord , , acNext
x = x - 1
Loop
When you say it errors before it starts to loop, is it when you execute the Docmd.GotoRecord statement? If so, it is likely to be because you have not stored the current record which has been updated. If the error is at the GotoRecord, add a save statement just before it:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Save ,,
-Stewart
Feb 27 '08 #2

NeoPa
Expert Mod 15k+
P: 31,769
Can you tell us which line the error occurs on and what the error message is?
Feb 28 '08 #3

P: 4
the error occurs at the "DoCmd.GoToRecord , , acNext"

I have added a save just before the DoCmd.GoToRecord , , acNext:
Expand|Select|Wrap|Line Numbers
  1.     Do While x > 0
  2.     Me.Check48 = True
  3.     DoCmd.Save
  4.     DoCmd.GoToRecord , , acNext
  5.     x = x - 1
  6.     Loop
However, this still results in the same error
Feb 28 '08 #4

NeoPa
Expert Mod 15k+
P: 31,769
... and what the error message is?
Feb 28 '08 #5

P: 4
Sorry...

Run-time error '2105':

You cant go to the specified record
Feb 28 '08 #6

NeoPa
Expert Mod 15k+
P: 31,769
I would have expected that Scott was right about the save. I can see no other reason why going to the next record might fail. Is there a next record? Maybe there are no more records in your recordset. I'm grasping at straws here as I really can't see the problem. I'm sorry.
Feb 28 '08 #7

Post your reply

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