473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Need to include Field List In Form, help!

Hey guys,
I have two main questions
First off (pictures are kind of blurry)
I have this table
http://i197.photobucket.com/albums/a.../DiscTable.jpg

And thats my database I use my Form on

I created a search form:
http://i197.photobucket.com/albums/a...SearchForm.jpg

Then created a listbox, selected a "field List" and got all of the header values from my table..
so its a box with every header from the table so if you look its like this:
http://i197.photobucket.com/albums/a...earchForm2.jpg


As you see, I turned on the multi-seclect feature to simple so I can select more than one

So from the original discform without the field list
I was able to select one or more sizes, click search then it will update the subform/table and show only those sizes,

so heres my two questions:
for the field list first of all, I dont want the first 2 things which are part #, size, just those pressures, so I don't need thsoe first two columns how do I make that show?

second:
heres my code from the search button,
that works with the size list,
but I need to integrate this Field list into the search button so it will also update, oh yeah and if it says NA under a pressures, insteaf of a number, I dont want that to show as a search result
so heres the code: what do I need to add to make this work?
code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3. Option Explicit
  4.  
  5. Private Sub btnClear_Click()
  6. Dim intIndex As Integer
  7.  
  8. ' Clear all search items
  9.  
  10.  
  11. ' De-select each item in Color List (multiselect list)
  12. For intIndex = 0 To Me.SizeList.ListCount - 1
  13. Me.SizeList.Selected(intIndex) = False
  14. Next
  15.  
  16. End Sub
  17.  
  18. Private Sub btnSearch_Click()
  19.  
  20. ' Update the record source
  21. Me.DiscForm.Form.RecordSource = "SELECT * FROM DiscTable " & BuildFilter
  22.  
  23. ' Requery the subform
  24. Me.DiscForm.Requery
  25. End Sub
  26.  
  27.  
  28. Private Sub Form_Load()
  29.  
  30. ' Clear the search form
  31. btnClear_Click
  32.  
  33. End Sub
  34.  
  35. Private Function BuildFilter() As Variant
  36. Dim varWhere As Variant
  37. Dim varSize As Variant
  38. Dim varItem As Variant
  39. Dim intIndex As Integer
  40.  
  41. varWhere = Null ' Main filter
  42. varSize = Null ' Subfilter used for colors
  43.  
  44.  
  45.  
  46. ' Check for Colors in multiselect list
  47. For Each varItem In Me.SizeList.ItemsSelected
  48. varSize = varSize & "[Size] = """ & _
  49. Me.SizeList.ItemData(varItem) & """ OR "
  50.  
  51. Next
  52.  
  53. ' Test to see if we have subfilter for colors...
  54. If IsNull(varSize) Then
  55. ' do nothing
  56. Else
  57. ' strip off last "OR" in the filter
  58. If Right(varSize, 4) = " OR " Then
  59. varSize = Left(varSize, Len(varSize) - 4)
  60. End If
  61.  
  62. ' Add some parentheses around the subfilter
  63. varWhere = varWhere & "( " & varSize & " )"
  64. End If
  65.  
  66. ' Check if there is a filter to return...
  67. If IsNull(varWhere) Then
  68. varWhere = ""
  69. Else
  70. varWhere = "WHERE " & varWhere
  71.  
  72. ' strip off last "AND" in the filter
  73. If Right(varWhere, 5) = " AND " Then
  74. varWhere = Left(varWhere, Len(varWhere) - 5)
  75. End If
  76. End If
  77.  
  78. BuildFilter = varWhere
  79.  
  80. End Function
  81.  
Someone please help me out with this, I would appreaciate it.
Jun 14 '07 #1
1 2434
MMcCarthy
14,534 Expert Mod 8TB
Then created a listbox, selected a "field List" and got all of the header values from my table..
so its a box with every header from the table so if you look its like this:
http://i197.photobucket.com/albums/a...earchForm2.jpg
I don't use the field list setting very often but I'm not aware of any way of restricting the list. However, you can also base the list on a query so create a query with just the fields you want to show in the list and set the query as the lists row source. This should solve that problem.

As for building the subforms recordsource, try the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch_Click
  2.     ' Update the record source
  3.     Me.DiscForm.Form.RecordSource "SELECT " & BuildSelect & " FROM DiscTable " & BuildFilter
  4.     ' Requery the subform
  5.     Me.DiscForm.Requery
  6. End Sub 
  7.  
  8. Private Function BuildSelect() As String
  9. Dim strSelect As String
  10. Dim varItem As Variant
  11.  
  12.     For Each varItem In Me.PressureList.ItemsSelected
  13.         strSelect = strSelect & Me.PressureList.ItemData(varItem) & ", " 
  14.     Next
  15.  
  16.     ' Remove the last comma
  17.     strSelect = Left(strSelect, Len(strSelect) - 2)
  18.  
  19.     BuildSelect = strSelect
  20.  
  21. End Function
  22.  
  23. Private Function BuildFilter() As String
  24. Dim strWhere As String
  25. Dim strPressure As String
  26. Dim varItem As Variant
  27.  
  28.     strWhere = "WHERE ("
  29.  
  30.     ' Check for Colors in multiselect list
  31.     For Each varItem In Me.SizeList.ItemsSelected
  32.         strWhere = strWhere & "[Size] = """ & _
  33.         Me.SizeList.ItemData(varItem) & """ OR "
  34.     Next
  35.  
  36.     ' set pressure criteria
  37.     For Each varItem In Me.PressureList.ItemsSelected
  38.         strPressure = strPressure & Me.PressureList.ItemData(varItem) & " <> 'N/A' AND " 
  39.     Next
  40.  
  41.     ' Remove last AND
  42.     strPressure = Left(strPressure, Len(strPressure) - 5)
  43.  
  44.     ' Test to see if we have subfilter for colors...
  45.     If strWhere = "WHERE (" Then
  46.         strWhere = strPressure & ")"
  47.     Else
  48.         ' strip off last "OR" in the filter
  49.         strWhere = Left(strWhere, Len(strWhere) - 4)
  50.         strWhere = strWhere & ") AND (" & strPressure & ")"
  51.     End If
  52.  
  53.     BuildFilter = strWhere
  54.  
  55. End Function
  56.  
Jun 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
2
by: Uninvisible | last post by:
I have put together a db for a law firm to keep track of counterfeit activities. There are four parent tables: tblContact tblTransaction tblAction tblFile I have created a form,...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
2
by: CW | last post by:
In an earlier thread, I was asking for help on "Invalid attempt to FieldCount when reader is closed" error when I was using a dataset rather than a datareader to bind to a datagrid. After...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.