Solved

combo box afterupdate problem

Posted on 2014-02-09
4
619 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
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Gustav Brock
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now