Solved

combo box afterupdate problem

Posted on 2014-02-09
4
633 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
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 49

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

830 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