Solved

Access listbox with multi select not saving values

Posted on 2014-04-16
8
2,031 Views
Last Modified: 2014-04-29
I’m trying to resolve an issue using list box with the multi select option
I have form with a tab control and a sub form
I have a multi select listbox on the parent form / 1st tab called ActionHistory
I have a combo boxes on both the parent and sub form on 2nd tab that have the same values as the ActionHistory listbox called ActionTaken & ActionTaken2

What I want to do is when an item is selected in either of the combo boxes I also want it selected in the list box.    I know the first question everyone will have is why?  Answer - Because the customer wants it.

The combo box on the sub form works – except that it shifts the focus to the list box on the 1st tab and ignores the set focus back to the subform.  I can create multiple child records on the subform and all of the selected ActionTaken entries are saved in the ActionHistory on the parent.

The combo box on the parent form DOES NOT WORK – it checks the box on the list but doesn’t actually save the selection – if you move to the next record and come back the item is no longer selected

I put the same code under a command button on the parent form – if you click it after selecting the item from the drop down the selection is saved

If I call the command button from the AfterUpdate of the drop it does not work

So if anybody can tell me what’s wrong or give me a better way to do this I'm open to all ideas

Here’s the relevant code

Sub form code that works – except for the setfocus comand
Private Sub ActionTaken2_AfterUpdate()
    Dim i As Variant
    For i = 0 To Me.Parent.ActionHistory.ListCount - 1
        If Me.Parent.ActionHistory.ItemData(i) = Me.ActionTaken2 Then
      Me.Parent.ActionHistory.Selected(i) = True
        End if
    Next
    Me.Remarks.SetFocus
End Sub

Parent form code – checks the box on the list but does not save value
Private Sub ActionTaken_AfterUpdate()
    Dim i As Variant
    For i = 0 To Me.ActionHistory.ListCount - 1
       If Me.ActionHistory.ItemData(i) = Me.ActionTaken Then
            Me.ActionHistory.Selected(i) = True
        End If
    Next
End Sub

Command button code that works when you click the button
Private Sub Command67_Click()
    Dim i As Variant
    For i = 0 To Me.ActionHistory.ListCount - 1
        If Me.ActionHistory.ItemData(i) = Me.ActionTaken Then Me.ActionHistory.Selected(i) = True
    Next
End Sub

Calling the command button from the AfterUpdate of the combo box – DOES NOT WORK
Private Sub ActionTaken_AfterUpdate()
        DoCmd.RunCommand acCmdSaveRecord
        Call Command67_Click
End Sub
0
Comment
Question by:CountryGirlMD
8 Comments
 
LVL 19

Expert Comment

by:Eric Sherman
Comment Utility
Can you load up a sample db ... would make it easier to understand and see exactly what needs to be done???

ET
0
 

Author Comment

by:CountryGirlMD
Comment Utility
Here's a sample of what I'm trying do
ListboxTest.accdb
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
First, the best advice I can possibly give you is to get rid of ActionHistory (the multi-valued field in Problems table).  Almost all of the regular Experts here would concur that MultiValued fields were a half-baked idea that Microsoft never should have introduced in Access 2007.  

- They are not compatible with other database platforms
- They encourage poor normalization

You are already handling the Action History correctly through your ProbUpdates table... by relating detail records for Actions to their parent records in the Problem table through the Problem ID field.

Is the goal of the listbox on the parent form simply to display which actions have taken place?

In addition to not working correctly, if the user selects or deselects items from the list box on your form, there will be a disconnect between the Actions stored in ProbUpdates (your subform) and the actions displayed in the list box.

If you really need to display a checkbox list of 'actions taken' you should:
1.  Get rid of the multivalued ActionHistory field from the Problems table
2.  Create a list of unbound checkboxes
3.  Base the Checkbox values on 'lookups' from your ProbUpdates table, with control sources such as (including the = sign):
     = DCount("*", "ProbUpdates", "Prob_ID = " & [Prob_ID] & " AND ActionTaken = 'Recall'")

Open in new window

4.  Prevent the user from selecting/deselecting the checkboxes (in order to prevent the disconnect I described earlier)
5.  Code the After Update event of the ComboBox to insert a new record into the ProbUpdates table:

Dim strSQL as string
strSQL = "INSERT INTO ProbUpdates (Prob_ID, ActionTaken) VALUES (" & Me,Prob_ID & ",'" & Me.ActionTaken & "')
CurrentDB.Execute strSQL, dbFailonError
Me.UpdateSF.Form.Requery

Open in new window


There are numerous other ways of displaying the list of actions taken, without using multivalued field... this is just one.
0
 
LVL 84
Comment Utility
<no points please>

I concur completely with mbizup - get rid of MVFs.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Assisted Solution

by:CountryGirlMD
CountryGirlMD earned 0 total points
Comment Utility
Thanks everybody for the responses, but nobody actually answered the question.

I’d never tried to use the multi select option on a bound list before because I KNOW it doesn’t follow normalization standards.   I was trying it in this case because of what the CUSTOMER wanted, I even stated this in the original problem description – ‘I know the first question everyone will have is why?  Answer - Because the customer wants it.’

The problem is the customer may have more than one action on each initial or follow up record & they don’t want to create extra follow ups just to document extra actions.

And while I would have liked to found an answer to why the code wasn’t working it’s now irrelevant.

After another discussion with the customer I was able to convince them that there was a better way to handle what wanted.  The action choices will be saved in a separate table – with a ‘one to many’ link to the parent record table with no relationship to the 'update records' and displayed in a single list box on the parent record’s form.
0
 

Author Comment

by:CountryGirlMD
Comment Utility
mbizup

I gave you the points for the effort toward alternate solutions
the B grade because I would have liked to know why the code didn't work
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
The original 'question' in your post as I understood it was:

"So if anybody can tell me what’s wrong or give me a better way to do this I'm open to all ideas"

So what I posted was an attempt at giving you a better, more workable structure... with a user interface like the customer wanted.

<<  but nobody actually answered the question. >>

I realize I didn't post anything near a complete solution, but was hoping for some feedback and clarification.

Fwiw, replying a week after we suggest solutions and immediately closing the question does not help us improve the suggestions posted.

Most of the regulars here do stay subscribed to our participated questions and will work with you towards better solutions - but it works best if you give us timely feedback (ideally within the same day) and a chance to follow up.
0
 

Author Closing Comment

by:CountryGirlMD
Comment Utility
mbizup

I gave you the points for the effort toward alternate solutions
the B grade because I would have liked to know why the code didn't work
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
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 …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

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

9 Experts available now in Live!

Get 1:1 Help Now