Solved

combo box afterupdate problem

Posted on 2014-02-09
4
638 Views
Last Modified: 2014-02-14
Dear experts -
Probably a silly error, but driving me nuts -
I have an unbound combo box, with a list of projects. In the after update, I call a procedure that sets the recordset on the form to that value as well as some other things.

NOW - I wanted to be in "if me.dirty" in the beforeupdate event, and cancel out if the user doesn't want to drop changes. This works fine, HOWEVER if the user opts to drop the changes, it is NOT firing the event in the afterupdate event.

any ideas?
THANKS!
0
Comment
Question by:terpsichore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39845448
This is by design and is the whole idea of cancelling - to not update, thus not fire the AfterUpdate event.

Move what you want to do in all cases into the BeforeUpdate event.

/gustav
0
 

Accepted Solution

by:
terpsichore earned 0 total points
ID: 39845466
but then I am getting an error in the called procedure -

Moving everything to the (unbound) combobox's beforeupdate:
Private Sub cboaccounts_BeforeUpdate(Cancel As Integer)

If Me.Dirty = True Then
     If MsgBox("Are you sure you wish to drop all changes and select a different account?", vbYesNo) = vbYes Then
        Me.Form.Undo
        setaccount False, Me.cboaccounts.Column(0)  'sets bookmark based on current ID
    Else
        Cancel = True
        Exit Sub
    End If
Else
    setaccount False, Me.cboaccounts.Column(0)
End If


End Sub

Open in new window


I get this error message:
"The macro or function set to the beforeupdate or validationrule property for this field is preventing... from saving the data to the field"

From this called procedure:
If newaccount = True Then
    DoCmd.GoToRecord , , acNewRec
    Me.txtCompanyName.SetFocus
    Me.cboaccounts = Null
    
    Me.sfContact.Visible = False
    
    
ElseIf Nz(Account_ID, 0) <> 0 Then

    Dim rst    As DAO.Recordset
    Dim I      As Integer
    Dim ctl    As Control

    Set rst = Me.RecordsetClone

    rst.FindFirst "account_ID=" & Me.cboaccounts.Column(0)

    If Not rst.NoMatch Then Me.Bookmark = rst.Bookmark

    'cleanup
    rst.Close
    Set rst = Nothing

    Me.sfContact.Visible = True
    Me.sfContact.Form.cbocontacts.Requery
End If

End Sub

Open in new window


Thanks!
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39845513
Can't quite follow your logic, but you may have to rethink this from the start.

If you have changed anything in the form, it will be dirty, so no reason to check for that.

If the user answers Yes you don't need to do anything in the BeforeUpdate event.
If the answer is No, you just need to set Cancel to True in the BeforeUpdate event.

/gustav
0
 

Author Closing Comment

by:terpsichore
ID: 39858527
sorry - I see the problem.
1) the procedure was referencing the control instead of the parameter
2) I found (surprise) that UNBOUND combo boxes cannot use an 'undo' feature to revert to the prior value (!). I had to declare a regional variable, set it on the combobox's gotfocus, and then reset in the afterupdate event of the combo box.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

617 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