473,399 Members | 3,656 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,399 software developers and data experts.

Why is my search form returning 1 record in my subform when there should be multiple?

I have a search form with a sub data form. When i search for "john" for example I should get a bunch of records in my subform, however it is just showing the first one from the table.

Here is the VBA.

Expand|Select|Wrap|Line Numbers
  1.  Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub btnClear_Click()
  5.     Dim intIndex As Integer
  6.  
  7.     ' Clear all search items
  8.     Me.txtID = ""
  9.     Me.txtLast = ""
  10.     Me.txtFirst = ""
  11.  
  12.  
  13. End Sub
  14.  
  15. Private Sub btnSearch_Click()
  16. Dim test As String
  17.  
  18.  
  19.     ' Update the record source
  20.     Me.FrmTest5.Form.RecordSource = "SELECT * FROM tblcastmemberinfo " & BuildFilter
  21.  
  22.  
  23.     ' Requery the subform
  24.     Me.FrmTest5.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.       varWhere = Null  ' Main filter
  38.  
  39.    ' Check for LIKE Perner
  40.    If Me.txtID > "" Then
  41.        varWhere = varWhere & "[Learner ID] LIKE '*" & Me.txtID & "*' AND "
  42.    End If
  43.  
  44.    ' Check for LIKE Last Name
  45.    If Me.txtLast > "" Then
  46.        varWhere = varWhere & "[Last] LIKE '*" & Me.txtLast & "*' AND "
  47.    End If
  48.  
  49.     ' Check for LIKE First Name
  50.    If Me.txtFirst > "" Then
  51.        varWhere = varWhere & "[First] LIKE '*" & Me.txtFirst & "*' AND "
  52.    End If
  53.  
  54.    ' Check if there is a filter to return...
  55.    If IsNull(varWhere) Then
  56.        varWhere = ""
  57.    Else
  58.        varWhere = "WHERE " & varWhere
  59.  
  60.        ' strip off last "AND" in the filter
  61.        If Right(varWhere, 5) = " AND " Then
  62.            varWhere = Left(varWhere, Len(varWhere) - 5)
  63.        End If
  64.    End If
  65.  
  66.    BuildFilter = varWhere
  67.  
  68. End Function 
Oct 18 '10 #1
4 1798
nico5038
3,080 Expert 2GB
I normally don't code this as I explain the user the right-click pop-up menu. Saved me a lot of time...

Best to run this code and place a breakpoint (click in left "ruler" to get a "dot") when the " AND " is truncated.

Use:
Expand|Select|Wrap|Line Numbers
  1. ?varWhere 
  2.  
in the immediate window to see the build expression.

Using the query appended with this expression you can copy/paste it in the query editor's SQL-text mode and see what happens.

Nic;o)
Oct 18 '10 #2
munkee
374 256MB
Ensure your subform is allowed to display more than one record also. Set it to be a continuous form or atleast have the record navigation buttons there.

I know this is obvious but sometimes it can be the simplest of things.
Oct 19 '10 #3
My subform is a tabbed subform; It has 3 tabs and the two last tabs show more then one. However the first record just shows one. I have it set to single form. I tried other forms but it they don't work or look right.
Oct 19 '10 #4
munkee
374 256MB
The first will only show one because it is set to single form. This means it will only show 1 record at a time. In order to view the rest you need to use record navigation buttons.

You can either add these via the control wizard (insert a command buttong and go through the record navigation wizard) or by setting the properties of the subform to "Record Navigation: yes" or true I forget the exact. However this will show a small toolbar at the bottom of the subform and will detail something like showing record 1 of 100 etc. You can then navigate through the other records using the arrow buttons.


If you wish to see all of the records you can try continuous form and set your textboxes etc all in one horizontal line. Then resize the forms detail section to be a similar height to the controls. When you view the subform in form view you will then see your records all listed.

I have attached an example of this with a before (in design view) and the after (when in form view)
Attached Images
File Type: jpg subfrmshow.jpg (33.1 KB, 135 views)
File Type: jpg after.jpg (21.1 KB, 192 views)
Oct 19 '10 #5

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

Similar topics

1
by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
8
by: yossi.kreinin | last post by:
Hi! When are multiple definitions of global variables with the same name considered legal in C, and how is it different from C++? It appears that in terms of assembly language, some C...
1
by: gleave | last post by:
Hi, I have a problem with subforms. I want to lock a subform until all the required data is inputted in the main form. The required fields in main form: Invoice Number Invoice to The main...
1
by: asavu | last post by:
Hello, I'm somewhat new to this, and I definately need some help. I have a db for a small business, and I have a main form, Customer Info, which has a subform Appliance Info, which has a subform...
2
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.