Solved

Access listbox with multi select not saving values

Posted on 2014-04-16
8
2,165 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 500 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 84
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

730 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