INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Update or CancelUpdate without AddNew or Edit.

Update or CancelUpdate without AddNew or Edit.

(OP)
I am working on a subroutine for a start button that is used to select jobs for processing. Jobs are selected one at a time. However, the jobs chosen by a given user should all be deselected if the button is clicked on for any of them.

My problem is that, if the first record is the one that is chosen for deselection I get error 3020, Update or CancelUpdate without AddNew or Edit. The error appears when this line of code runs:

Me.ElapsedTimeBox = elBox + elTime

Here is the code for the whole subroutine:

Private Sub StartBtn_Click()
Dim db As Database
Dim rs, rs2, rscl As Recordset
Dim rCount As Long
Dim stTime As Date
Dim elTime As Long
Dim elBox As Long

Set db = CurrentDb()

If Me.RedTag = 0 Then
rCount = 0

Set rs = db.OpenRecordset("Select RedTag From CNCApprovedOrdersQuery " & _
"Where RedTag = " & UserID, dbReadOnly)

rCount = rs.RecordCount

rs.Close
Set rs = Nothing

If rCount = 0 Then
If IsNull(Me.StartTimeBox) Then
Me.StartTimeBox = Now()
'copy the value into temporary location for further calculations if PAUSE will be pressed at any time.
Me.PausePressedTime = Now()
Me.RedTag = UserID
Else
'if record had been timestamped, ask user whether he wants to make a change
'put a new timestamp if YES is chosen
Me.PausePressedTime = Now()
Me.RedTag = UserID
End If
Else
If MsgBox("Do you want to run a simultaneous job?", vbYesNo) = vbYes Then
'copy the value into temporary location for further calculations if PAUSE will be pressed at any time.
Me.PausePressedTime = Null
Me.RedTag = UserID
Else
MsgBox "Job Cancelled", vbInformation
End If
End If
Else
Me.PauseDepressedTime = Now()

Set rs = db.OpenRecordset("Select * From CNCApprovedOrdersQuery " & _
"Where RedTag = " & UserID, dbReadOnly)

rCount = rs.RecordCount

rs.FindFirst Not IsNull(rs!PausePressed)

If rs.NoMatch = False Then
stTime = rs!PausePressed

Interval = DateDiff("n", stTime, Now())

elTime = Interval / rCount
End If

rs.Close
Set rs = Nothing

Set rscl = Me.RecordsetClone

rscl.MoveLast

Do While Not rscl.BOF
If rscl!RedTag = UserID Then
Me.Bookmark = rscl.Bookmark
elBox = Me.ElapsedTimeBox
Me.ElapsedTimeBox = elBox + elTime
Me.RedTag = 0
End If

rscl.MovePrevious
Loop

rscl.Close
Set rscl = Nothing
End If

Me.Refresh
End Sub


RE: Update or CancelUpdate without AddNew or Edit.

You should really start using TGML tags for code.

So if you do this:

CODE

Set rscl = Me.RecordsetClone

rscl.MoveLast

Do While Not rscl.BOF
    If rscl!RedTag = UserID Then
        Me.Bookmark = rscl.Bookmark
        elBox = Me.ElapsedTimeBox

        Debug.Print "elBox has a value of " & elBox
        Debug.Print "elTime has a value of " & elTime

        Me.ElapsedTimeBox = elBox + elTime
        Me.RedTag = 0
    End If

    rscl.MovePrevious
Loop 

What are the values of the 2 variables at the time when you get the error?

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close