Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code not executing after a loop around a number of records

Status
Not open for further replies.

mozgheib

Programmer
Dec 14, 2003
50
KW
Hello,

I have a sub that loops around a number of records displayed by a form. In side that code anything I put
after the loop does not get executed. Any hints?
In my example below I want after the loop is finished
to go back to the original position the form was at when the user called the routine by clicking a button.

Thanks.


Dim lastposition As String
Me.BacktoMenu.SetFocus
Me.ValidateSelected.DefaultValue = 0
Me.ValidateSelected.Enabled = False

DoCmd.GoToRecord , , acFirst


Do While Me.CurrentRecord <> 0

If Me.VALIDATED = 2 Then

Me.VALIDATED = 1



If SRC_FLAG.Value = "PHD" Then
MODIFIED_PHD_CONFIDENCE.Value = 100
DAYINSERTED.Value = Now()
MODIFIEDBY.Value = Forms!OrionLogonScreen!UserName
End If

End If


DoCmd.GoToRecord , , acNext

Loop
'This code below is not executing or anything I put after the loop.
lastposition = Me.CurrentRecord
DoCmd.GoToRecord , , acGoTo, lastposition
 
Hello,

I think your problem is because you are looping and including the last record in your loop, so when you come out of the loop there is no current record.....do you have error trapping turned on somewhere because it seems like it is failing and then going to an error loop.

Regards

Andrew
 
Hi,

As a matter of fact I copied the code wrong. The lastposition assignment is happening inside the loop.

Now I can't trace the code in design mode I get error
2499 can't use goto method on an object in design mode.

I get the error when it hits the goto first record.

my code looks now like this :

Dim lastposition As String
Me.BacktoMenu.SetFocus
Me.ValidateSelected.DefaultValue = 0
Me.ValidateSelected.Enabled = False

lastposition = Me.CurrentRecord
DoCmd.GoToRecord , , acFirst


Do While Me.CurrentRecord <> 0

If Me.VALIDATED = 2 Then

Me.VALIDATED = 1



If SRC_FLAG.Value = "PHD" Then
MODIFIED_PHD_CONFIDENCE.Value = 100
DAYINSERTED.Value = Now()
MODIFIEDBY.Value = Forms!OrionLogonScreen!UserName
End If

End If


DoCmd.GoToRecord , , acNext

Loop


DoCmd.GoToRecord , , acGoTo, lastposition
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top