Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access listbox with multi select not saving values

Posted on 2014-04-16
8
Medium Priority
?
2,300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40005551
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
ID: 40005717
Here's a sample of what I'm trying do
ListboxTest.accdb
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1500 total points
ID: 40006202
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 85
ID: 40006285
<no points please>

I concur completely with mbizup - get rid of MVFs.
0
 

Assisted Solution

by:CountryGirlMD
CountryGirlMD earned 0 total points
ID: 40021665
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
ID: 40021677
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
ID: 40021705
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
ID: 40029081
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

719 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