having trouble with cancel

J

jon

Hi
I can not get a cancel to work I have try a few variations but it still wont
work.
I have pasted the code below.

thanks

Jon


Private Sub ButUpdate_Click()
On Error GoTo Err_ButUpdate_Click

Dim db As DATABASE
Dim rst As Recordset
Dim blnok As Boolean


If Me![CmbFreeStsteStatus] = 2 Then
Me![ChkFreeststateDone] = -1
Set db = CurrentDb()
Set rst = db.OpenRecordset("ComponentNos", dbOpenTable)

With rst
rst.Index = "Componet No"
rst.Seek "=", [CmbJob]
.Edit
.Fields("FreeStateCount") = .Fields("FreeStateCount") + 1
.Fields("FreeStatePassCount") = .Fields("FreeStatePassCount") +
1
.Update

End With

ElseIf Me![CmbFreeStsteStatus] = 3 Then ' job requires free stating
If Me![FreeStatePassFail] = 0 Then

blnok = confirm(" Are You sure the Job has Failed?")
If blnok = False Then
Cancel '***** the offending line
*****
Else
Me![CmbFreeStsteStatus] = 4
Me![ChkFreeststateDone] = -1
Set db = CurrentDb()
Set rst = db.OpenRecordset("ComponentNos", dbOpenTable)

With rst
rst.Index = "Componet No"
rst.Seek "=", [CmbJob]
.Edit
.Fields("FreeStateCount") = 0
.Fields("FreeStatePassCount") = 0
.Update

End With

End If
End If

End If

DoCmd.Close

Exit_ButUpdate_Click:
Exit Sub

Err_ButUpdate_Click:
MsgBox Err.Description
Resume Exit_ButUpdate_Click

End Sub
Private Sub CmbUndoClose_Click()
On Error GoTo Err_CmbUndoClose_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_CmbUndoClose_Click:
Exit Sub

Err_CmbUndoClose_Click:
MsgBox Err.Description
Resume Exit_CmbUndoClose_Click

End Sub
 
A

Allen Browne

What's cancel? There's no statement by that name, no procedure we can see,
no argument provided by the Click event, no variable being set.

How about if you replace:
If blnok = False Then
Cancel
Else
with:
If blnok <> False Then

Or did you want to cancel the entire operation?
If so, you will need to OpenTrans and then Rollback.
Here's an example of using a transaction, and a discussion of the pitfalls:
http://allenbrowne.com/ser-37.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top