Solved

combo box afterupdate problem

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

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

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

867 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

13 Experts available now in Live!

Get 1:1 Help Now