Solved

combo box afterupdate problem

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 5 53
Access query expression 6 19
DCount Type Mismatch 2 21
Setting Macro in Access to Automate Running an Append at a Certain Time 2 17
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…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

815 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

12 Experts available now in Live!

Get 1:1 Help Now