473,765 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching for records in a form based on criteria in a subform

I would like to be able to place a command button on a primary
(parent) form that opens up a subform. I want to use this subform to
search for or limit the recordset of data in the primary form. The
database is setup as follows: the primary form is named
"TestDataCleanu p" which is based on a table named "Test_Resul ts". This
primary form has multiple subforms associated with it, including
"Names_Disp lay" and "SiteAddresses_ Display". The tables for these two
subforms are "Names" and "Total_Site_Add ress" and have relationships
with the "Test_Resul ts" table (Names is one-to-many,
Total_Site_Addr ess is one-to-one).

Currently I have two fields in the primary form that are used to limit
the recordset in the "TestDataCleanu p" form. The first is named
"txtNameFil t" and is an unbound text box where I have the user enter
in a last name and when they click enter, it limits the recordset in
the primary form to those records with that last name. The field
"TestID" is the related field between the "Names" table and the
"Test_Resul ts" table. The "LASTNAME" field contains the last name of
the individual in the record. The code that allows me to do this is:

Private Sub txtNameFilt_Aft erUpdate()
Dim strSQL As String
If IsNull(Me.txtNa meFilt) Then
Me.RecordSource = "Test_Resul ts"
Else
strSQL = "SELECT DISTINCTROW Test_Results.* FROM Test_Results " &
_
"INNER JOIN Names ON " & _
"Test_Results.T estID = Names.TestID " & _
"WHERE Names.LASTNAME = '" & Me.txtNameFilt & "';"
Me.RecordSource = strSQL
End If
End Sub

The second field is named "cboSiteAdd LU" and is an unbound combobox
with the row source being a query named "SiteAddressFor Display". This
query selects data from the "Total_Site_Add ress" table and is the
source query for the
"SiteAddresses_ Display" subform. The query contains three fields:
TestID, ADDTOTAL, and SITELOC; with the bound column in the combo box
being ADDTOTAL. TestID is the related field between the
"Total_Site_Add ress" and the "Test_Resul ts" tables. The ADDTOTAL
field contains address information (ex."W123 Bob Road"). The SITELOC
field contains the municipality location of the site address.

Currently the user can select an address from the combobox and the
recordsource will be limited in the primary form ("TestDataClean up")
to those that contain the address choosen. The code for this is as
follows:

Private Sub cboSiteAddLU_Af terUpdate()
Dim strSQL As String
Dim strAddr As String

If IsNull(Me.cboSi teAddLU) Then
' If the combo is Null, use the whole table as the
RecordSource.
Me.RecordSource = "Test_Resul ts"
Else
strAddr = Me.cboSiteAddLU
'Escape any single-quotes.
strAddr = Replace(strAddr , "'", "''")

strSQL = "SELECT DISTINCTROW Test_Results.* FROM Test_Results
" & _
"INNER JOIN SiteAddressForD isplay ON " & _
"Test_Results.T estID = SiteAddressForD isplay.TestID " & _
"WHERE SiteAddressForD isplay.ADDTOTAL = '" & strAddr & "'"
Me.RecordSource = strSQL
End If
End Sub

As stated above, I would like to be able to move these two functions
onto another subform. I want the user to be able to click a command
button, open up a subform, and then basically perform the same
filtering as is being done now with the lookup fields currently in
primary form. Thank you in advance for any advice.
Nov 13 '05 #1
0 1438

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2485
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm satified with the table structure. I've moved on to building some front ends for our users. I'm running into situations where I want subreports to be built from queries that are dependent on the values in other controls. I've played with stored...
3
2042
by: Daniel Tan | last post by:
Hi, i got a subform and inside got some records. But i want to press a button and make all those records to a report. It only display all those records with same Job Order no. I want to display all job order no. and part. Pls advise. partid = " = '" & Forms!main!Overdue_sub.Form!Part_No & "' " MyReport = "select * from overdue_qry " & _ "where" & " = '" & Forms!main!Overdue_sub.Form!Jobid
2
3757
by: Craig M | last post by:
Hi, I have a form, frmInvoices and a subform, frmInvoicesSub. On the parent form, i have a "print report" button, that prints a report depending on an ID on the parent form. Each record in the subform has a check box, "invoiced". Currently, my print report button has the folowing code:
8
1604
by: David | last post by:
Hi, I have a form as follows: Main Form (To Select Customer) Sub Form 1 (To Select PO Number, by clicking on field) - Continuous form Sub Form 2 (To view order details)- Continuous form ______________________
0
1546
by: Jason | last post by:
I would like to be able to place a command button on a primary (parent) form that opens up a subform. I want to use this subform to search for or limit the recordset of data in the primary form. The database is setup as follows: the primary form is named "TestDataCleanup" which is based on a table named "Test_Results". This primary form has multiple subforms associated with it, including "Names_Display" and "SiteAddresses_Display". The...
1
2397
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting about 80 records from the Orders table. 80 out of a 1000 records. Now our data entry form shows our customer addresses, but not customer order history. When looking at all of the tables, customer, payments, orders, they still have all of the...
1
1396
by: keri | last post by:
Hi and apologies for duplicates. I am having some posting issues so thought i'd start afresh. Please treat me as a beginner so I get very simple explanations! The below is driving me crazy; I want a form (frm book appointment) that has a subform with a datasheet table / query (all customer records). I want to be able to enter search terms in up to 6 textboxes on my main
7
4539
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
1
4286
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on another main and sub form. The requery on the sub form and refresh comands on the main form do not work when the form is first displayed and when the selection criteria is changed. Should I be doing a refresh and then repaint of the sub form. ...
0
9398
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,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
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
5275
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
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
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.