Solved

Using List boxes to query a form will only show info for criteria not the rest of the fields. Error Name!? for other fields

Posted on 2013-11-01
9
367 Views
Last Modified: 2013-11-17
This code allows a user to select criteria as many as they need In 3  List Boxes. Then that information is suppose to populate a Sub form.

The data that is selected shows the criteria that is selected but doesnt show the information for the rest of the fields in the subform. Where and how do I put the code to join the forms to work together and show all the data for the subform?

Below is the code the tables were linked so I had to change them.

 Dim sf As SubForm
    Dim MODKitStr As String, DIVStr As String, BdeStr As String
    Dim SQLStr As String
    Dim ListCounter As Integer
    Dim AnItem As Variant
     
    For Each AnItem In Me.lstMODKit.ItemsSelected
        If Not IsNull(AnItem) Then
            MODKitStr = MODKitStr & "'" & Me.lstMODKit.ItemData(AnItem) & "',"
        End If
    Next AnItem
    If Len(MODKitStr) = 0 Then
        Call noselection("A")
        Exit Sub
    Else
        MODKitStr = Left(MODKitStr, Len(MODKitStr) - 1)
    End If
     
    For Each AnItem In Me.lstDIV.ItemsSelected
        If Not IsNull(AnItem) Then
            DIVStr = DIVStr & "'" & Me.lstDIV.ItemData(AnItem) & "',"
        End If
    Next AnItem
    If Len(DIVStr) = 0 Then
        Call noselection("B")
        Exit Sub
    Else
        DIVStr = Left(DIVStr, Len(DIVStr) - 1)
    End If
       
    For Each AnItem In Me.lstBde.ItemsSelected
        If Not IsNull(AnItem) Then
            BdeStr = BdeStr & "'" & Me.lstBde.ItemData(AnItem) & "',"
        End If
    Next AnItem
    If Len(BdeStr) = 0 Then
        Call noselection("C")
        Exit Sub
    Else
        BdeStr = Left(BdeStr, Len(BdeStr) - 1)
    End If
    SQLStr = "SELECT tblMODHistory.Bde,tblMODHistory.DIV,tblMODHistory.[MOD Kit]   " & _
    "FROM qryMODHistory " & _
    "WHERE qryMODHistory.Bde IN(" & BdeStr & ") and qryMODHistory.DIV IN(" & DIVStr & ") and qryMODHistory.[MOD Kit] IN(" & MODKitStr & ")"
    Set sf = Me.[qryMODHistory_Crosstab subform]
    Debug.Print SQLStr
    sf.Controls.Parent.RecordSource = SQLStr
    sf.Requery

   End Sub
Private Sub noselection(LType As String)
    Dim msg As String
    Select Case LType
    Case Is = "A"
        msg = "No MOD Kits "
    Case Is = "B"
        msg = "No DIvision "
    Case Is = "C"
        msg = "No Brigade "
    Case Else
        msg = "Error : Do not know list box type :"
        End Select

    Me.[qryMODHistory_Crosstab subform].Controls.Parent.RecordSource = "SELECT qryMODHistory.Bde  ,qryMODHistory.DIV, qryMODHistory.[MOD Kit] FROM qryMODHistory WHERE qryMODHistory.[MOD Kit]  = '£$^'"
    Me.[qryMODHistory_Crosstab subform].Requery
    msg = msg & "have been selected" & vbCrLf & "Record was not updated"
    MsgBox msg
End Sub
 


Private Sub lstMODKit_AfterUpdate()
    Call DoubleMultiSelect_Click
End Sub
 
 
Private Sub lstDIV_AfterUpdate()
    Call DoubleMultiSelect_Click
End Sub

Private Sub lstBde_AfterUpdate()
    Call DoubleMultiSelect_Click
End Sub


exampleHelpwithListSearch.zip
0
Comment
Question by:gigifarrow
  • 6
  • 3
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39617463
test this,

note that --some of the columns in your query are not valid...
HelpwithListSearchRev.accdb
0
 

Author Comment

by:gigifarrow
ID: 39617647
Thank you for your time and help. I tried that rev database and Im still getting #Name?.

Can you tell what do you mean by some of my columns are not valid? What is making them not valid?
0
 

Author Comment

by:gigifarrow
ID: 39617657
Can you tell me what you changed on the example database please? Thanks in advance.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39617881
open the one that you uploaded and you will see the error when you open the form.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39617886
<Can you tell me what you changed on the example database please? Thanks in advance. >

open the form vba module,

look for the lines i commented,
the change is the line below/above the commented lines
0
 

Author Comment

by:gigifarrow
ID: 39621485
I saw the changes you made and I Incorporated them in my database. However, I am still getting the error #NAME?

You see the form is a crosstab query. The columns are in a field called Model. So instead of showing these fields under model, in the query it is shown as a individual column.


How do I make the Crosstabform work with the selections?

example
0
 

Author Comment

by:gigifarrow
ID: 39621681
I dont understand why you changed it from Sub Form to form. It stills is showing the same error messages.
0
 

Accepted Solution

by:
gigifarrow earned 0 total points
ID: 39641684
I will give myself credit because I figured it out on my own. The problem was I needed to make the query from the same table.
0
 

Author Closing Comment

by:gigifarrow
ID: 39654299
I figured out the answer to my own question.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

856 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