[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem deleting record with unbound controls that are updated by the "on current" event

Posted on 2004-11-23
4
Medium Priority
?
426 Views
Last Modified: 2008-02-01
I used the access wizard to place a delete record button on the form.  It worked fine until I added an unbound control to the form that I updated via the on current event.

I modified the cmdDelete button's event as follows:
 *** The error I get is Runtime Error 3167.  The record is deleted  ****
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

    ' Delete the item
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    ** !!!! ON CURRENT EVENT FIRES HERE !!! CAUSING AN ERROR **

' rest of code cut for brevity reasons
End Sub

' Here is my On Current event
Private Sub Form_Current()
    ' Used for navigation buttons
    acbHandleCurrent Me ' This code executes fine.
    HandleUnboundControls   ' This code raises error
 
End Sub

' Update any unbound controls on the form
Private Sub HandleUnboundControls()
    ** Code below raises error at the evaluation of the if statement when I first read Recordset.absoluteposition
    ** if I press continue the code contines without further error.  Any thoughts???
    If (Recordset.AbsolutePosition = -1) Then
        cmbItem = Null
        cmbDescription = Null
    Else
        cmbItem = Recordset!ITEM
        cmbDescription = Recordset!DESCRIPTION
    End If
   
 End Sub
0
Comment
Question by:robf
  • 2
4 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12655527
AbsolutePosition only applies to Snapshot type recordsets - what type is your form's recordset?
0
 

Author Comment

by:robf
ID: 12655599
It's an access query called "Catalog Extended" that contains fields from a table called "Catalog" such as ITEM, and [MATERIAL COST] as well as some calculated fields such as [UNIT PRICE] which is (([MATERIAL MARKUP]+[LABOR MARKUP]))
0
 

Author Comment

by:robf
ID: 12655645
Is there a way to test for deleted record?
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 750 total points
ID: 12655719
try this change to your code:


Private mblnDeleteing as Boolean

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

    ' Delete the item
    mblnDeleteing = Trye
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    mblnDeleteing = False
    ** !!!! ON CURRENT EVENT FIRES HERE !!! CAUSING AN ERROR **

' rest of code cut for brevity reasons
End Sub

' Here is my On Current event
Private Sub Form_Current()
    ' Used for navigation buttons
    acbHandleCurrent Me ' This code executes fine.
    If Not  mblnDeleteing  Then  ' only execute the next line when NOT deleting Records
         HandleUnboundControls   ' This code raises error
    End if
End Sub

' Update any unbound controls on the form
Private Sub HandleUnboundControls()
    ** Code below raises error at the evaluation of the if statement when I first read Recordset.absoluteposition
    ** if I press continue the code contines without further error.  Any thoughts???
    If (Recordset.AbsolutePosition = -1) Then
        cmbItem = Null
        cmbDescription = Null
    Else
        cmbItem = Recordset!ITEM
        cmbDescription = Recordset!DESCRIPTION
    End If
   
 End Sub


AW
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question