4 Replies - 6297 Views - Last Post: 28 January 2013 - 11:09 AM

#1 depricated  Icon User is offline

  • Derpicorn

Reputation: 823
  • View blog
  • Posts: 2,650
  • Joined: 13-September 08

Error 2491 Only After Deleting a Record

Posted 28 January 2013 - 10:23 AM

I feel like I must be overlooking something basic here. I have a form bound to a query, and I'm able to navigate it just fine via a combobox for the most part. However, when I attempt to delete records from the form it gives error 2491: The action or method is invalid because the form or report isn't bound to a table or query.

This is when I attempt to use SearchForRecord with a filter. It works any other time. Here's my code:

Private Sub cmdDeleteRecord_Click()

    If Not (Form.NewRecord) Then
        DeleteRecord
    Else
        If (Form.Dirty) Then
            DoCmd.RunCommand acCmdUndo
        End If
    End If
    LoadCurrentBCM
    
End Sub

Private Sub DeleteRecord()
    If Not (strEmpName.OldValue = txtBCMName.Value) Then
        DoCmd.RunCommand acCmdDeleteRecord
    Else
        MsgBox "You cannot delete yourself."
    End If
End Sub


Private Sub LoadCurrentBCM()
    Dim BCM As String
    BCM = DLookup("lngEmpID", "tblCurrentBCM")
    'cboBCMs = BCM
    'lngEmpID = BCM
    'strEmpName = Me.txtBCMName
    cboBCMs = BCM
    Me.Requery
    DoCmd.SearchForRecord , , acFirst, "[lngEmpID] = '" & BCM & "'" 'ERROR HERE
    RequeryBCMs
End Sub

Public Sub UpdateBCMs()
    If Me.Dirty = True Then DoCmd.RunCommand acCmdUndo
    DoCmd.SearchForRecord , , acFirst, "[lngEmpID] = '" & cboBCMs & "'"
End Sub

Private Sub RequeryBCMs()
    Me.cboBCMs.Requery
    Me.lstChangeLog.Requery
    Me.lstLoginLog.Requery
End Sub



The LoadCurrentBCM sub is kinda messy as I've been trying different things with it. The UpdateBCMs sub works flawlessly, and the LoadCurrentBCM sub even works if I do not delete the record (if it's still a new record and only does Undo instead). I'm at a loss as to why it fails after deleting a record but not any other time. Been fighting with this for a couple hours now, a fresh perspective will be greatly appreciated.

And the form IS bound to a query (qryBCM)

Is This A Good Question/Topic? 0
  • +

Replies To: Error 2491 Only After Deleting a Record

#2 depricated  Icon User is offline

  • Derpicorn

Reputation: 823
  • View blog
  • Posts: 2,650
  • Joined: 13-September 08

Re: Error 2491 Only After Deleting a Record

Posted 28 January 2013 - 10:38 AM

Derp. I figured it out.

There's a confirmation dialogue that pops up whenever I delete a record. I need to set focus back to the form first.

So here's my new LoadCurrentBCM sub. Works like a charm.

Private Sub LoadCurrentBCM()
    cboBCMs = DLookup("lngEmpID", "tblCurrentBCM")
    Me.lngEmpID.SetFocus
    DoCmd.SearchForRecord , , acFirst, "[lngEmpID] = '" & cboBCMs & "'"
    RequeryBCMs
End Sub

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3608
  • View blog
  • Posts: 12,397
  • Joined: 12-December 12

Re: Error 2491 Only After Deleting a Record

Posted 28 January 2013 - 10:56 AM

FYI
If you are referring to an Access confirmation dialog then you can disable it temporarily:

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True


This way you might replace the default message with your own MsgBox.

But you probably know this already :)
Was This Post Helpful? 1
  • +
  • -

#4 depricated  Icon User is offline

  • Derpicorn

Reputation: 823
  • View blog
  • Posts: 2,650
  • Joined: 13-September 08

Re: Error 2491 Only After Deleting a Record

Posted 28 January 2013 - 11:07 AM

View Postandrewsw, on 28 January 2013 - 10:56 AM, said:

FYI
If you are referring to an Access confirmation dialog then you can disable it temporarily:

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True


This way you might replace the default message with your own MsgBox.

But you probably know this already :)/>

Yep! All the same, thank you for the insight. Admittedly I am being lazy by just using the default confirmation dialogue. I'll go in and do a custom window on the next release - I'm just patching up holes in this one, we're aiming to have out by Friday. It's pretty solid, not running in to many problems, but this one was stumping me.

I like following up and posting my resolution when I do stuff like that so that later when others have a similar problem they can find my solution by searching rather than having to ask.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3608
  • View blog
  • Posts: 12,397
  • Joined: 12-December 12

Re: Error 2491 Only After Deleting a Record

Posted 28 January 2013 - 11:09 AM

Quote

I like following up and posting my resolution when I do stuff like that so that later when others have a similar problem they can find my solution by searching rather than having to ask.


That's good. I wish more took this attitude. Good luck.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1