473,698 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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 1811
nico5038
3,080 Recognized Expert Specialist
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 Contributor
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
Kelly Warden
7 New Member
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 Contributor
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, 140 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
3055
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 (frmBookingBookingBased), start a new record, and copy some values form the form into some fields in the subform, and then leave the cursor sitting (in focus) at the begining of the subform.
4
7013
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 user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
0
2700
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 form. Then I have 3 pages on a tab control ( 4 if the type of candidate validates that is is to be shown) Each page has a subform. The subforms can be either single or continuous, I think I am still deciding what I want to lock down this entry...
8
3302
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 definitions are translated to "weak" symbols, in which case multiple definitions are merged by the linker, while some become "normal" symbols, triggering linker errors in case they are defined more then once. Is it true that in C++, multiple definitions...
1
1806
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 form is called: Invoicing And the subform is called:
1
1664
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 Service Call Info... these three forms are linked, and I run into a problem when I try to search through records. I set up a different form where the user can select a customer, after which he can either push a button and using that customer's...
2
2745
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 listbox for users to select and search for counties. On the same page however I would like to integrate a similar multiselect box for nationality. I would like the user to be able to search for nationality with county or individually. After...
6
4666
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 for 2 list boxes:- county and nationality, while trying to add a third multi select list box for qualifications search is where i encounter my problem. I've copied the working code from my working list boxes, however it cant seem to pick up the...
1
6796
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 bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from multiple sources eg ,multi select list boxes , combo boxes. I have a subform showing all the...
0
8671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8598
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.