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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors deleting within subform

Status
Not open for further replies.

debbieg

Technical User
Dec 2, 2002
190
US
When I delete the last record on a subform, it deletes the record but I get the following error:

2465
Access can't find the field "|" referred to in your expression.

And if I delete the only record on a subform, it deletes the record but I get the following error:

2185
You can't reference a property or method for a control unless the control has the focus.

Here's the code behind my Delete button:
Code:
Private Sub cmdDelete_Click()
    On Error GoTo GotError
    If Not Me.NewRecord And Me.Dirty Then
        CompleteMsg
        Exit Sub
    End If

    msg1 = "You are about to delete "
    msg2 = Me.Parent!Employee_combo.Column(1)
    msg3 = "Date: " & Me.WorkDate & ", Temp Dept: " & Me.TempDept & ", Reg Hrs: " & Me.TempDeptRegHrs & ", O/T Hrs: " & Me.TempDeptOTHrs
    msg4 = "Are you sure you want to do this?  You will not be able to undo if you choose Yes."
    style = vbCritical + vbYesNo + vbDefaultButton2
    Response = MsgBox(msg1 & msg2 & vbCrLf & msg3 & vbCrLf & vbCrLf & msg4, style, conTitle)
    If Response = vbYes Then
        Me.AllowDeletions = True
        DoCmd.SetWarnings False 'turn system messages off
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True 'turn system messages on
        Me.AllowDeletions = False
        Me.cmdAdd.SetFocus
    End If
        

ExitSub:
    Exit Sub

GotError:
    If Err.Number = 2046 Then Resume ExitSub
    MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & "cmdDelete"
    Resume ExitSub
End Sub

If I comment out the "On error goto GotError" line, it goes to the "DoCmd.RunCommand acCmdDeleteRecord" line.

It's probably something very simple but I'm just not seeing it.

Thanks,
Debbie
 
How are ya debbieg . . . . .

Both errors are indicitive of [blue]some other code[/blue] trying to something. I would [purple]set a breakpoint[/purple] in the code and single step till the error comes up, or, [purple]is the debugger stopping on a line?[/purple]

Is there some code in your forms [blue]Current event?[/blue]

Calvin.gif
See Ya! . . . . . .
 
TheAceMan1,

I did set a breakpoint and it stops at "DoCmd.RunCommand acCmdDeleteRecord".

If I put
If Err.Number = 2465 Then Resume ExitSub
If Err.Number = 2185 Then Resume ExitSub
in my error trapping, everything works fine.

Thanks,
Debbie

 
OK debbieg . . . . .

Rem out youe error checking & try this:

In the database window click [blue]Tools[/blue] - [blue]Options[/blue] - [blue]Edit/Find Tab[/blue]. In the [purple]confirm section[/purple] put a [blue]checkmark[/blue] in [purple]Document deletions.[/purple]

Calvin.gif
See Ya! . . . . . .
 
Hmmm

Well, one thing to consider is corruption in the form. Copy the form to a new form and use the Access deletion button. Try a deletion. Then copy the code to the new form, and try deleting again.

Another thing to consider is if there are any relationships on your form associated with other records.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top