I am having trouble setting up a filter on my form. I have two tables that are linked through a text field (contact_id). This field is a combination of two other text fields (first_name and last_name).
When information is entered into my forms it is entered based on the two firled first_name and last_name. (which are already entered). It would be nice if second field on the form (first_name) was filtered by the selection made in last_name.
Currently I have createda form (Form2) and the two combo boxes are cboLName and cboFName. The name of the table that containts this information in tblContact_ID and the three text fields in the table are Contact_ID, first_name, and last_name.
cboLName has last_name as its rowsource
cboFName has first_name and last_name as its rowsource
cboLName has this AfterUpdate events proceedure:
Private Sub cboLName_AfterUpdate()
Dim lName As String
lName = "SELECT [tblContact_ID].[first_name], [tblContact_ID].[last_name] " & _
"FROM tblContact_ID " & _
"WHERE [last_name] = " & Me.cboLName.Value
Me.cboFName.RowSource = fName
Me.cboFName.Requery
End Sub
However this does not work, if I select the last name on the form then I get a select statement error. Could anyone please help me.
Thanks
Jackie
9 2350
Try this: -
Dim str as String
-
-
str = "SELECT [first_name], [last_name] FROM tblContact_ID" & _
-
" WHERE [last_name] = '" & Me.cboLName.Value & "'"
-
-
Me.cboFName.RowSourceType = "Table/Query"
-
Me.cboFName.RowSource = str
-
Me.cboFName.ColumnCount = 2
-
Me.cboFName.Requery
-
End Sub
-
You need to put single quotation marks on either side of Me.cboLName.Value because it's a string
I am having trouble setting up a filter on my form. I have two tables that are linked through a text field (contact_id). This field is a combination of two other text fields (first_name and last_name).
When information is entered into my forms it is entered based on the two firled first_name and last_name. (which are already entered). It would be nice if second field on the form (first_name) was filtered by the selection made in last_name.
Currently I have createda form (Form2) and the two combo boxes are cboLName and cboFName. The name of the table that containts this information in tblContact_ID and the three text fields in the table are Contact_ID, first_name, and last_name.
cboLName has last_name as its rowsource
cboFName has first_name and last_name as its rowsource
cboLName has this AfterUpdate events proceedure:
Private Sub cboLName_AfterUpdate()
Dim lName As String
lName = "SELECT [tblContact_ID].[first_name], [tblContact_ID].[last_name] " & _
"FROM tblContact_ID " & _
"WHERE [last_name] = " & Me.cboLName.Value
Me.cboFName.RowSource = fName
Me.cboFName.Requery
End Sub
However this does not work, if I select the last name on the form then I get a select statement error. Could anyone please help me.
Thanks
Jackie
Thank you very much I was so frustrated with that. It works perfectly
If I want to filter another field based on both last_name and first_name (the field is incident_date) can I just add an AND clause to the WHERE statement and include both conditions?
str = "SELECT [incident_date] FROM tblContact_ID" & _
" WHERE [last_name] = '" & Me.cboLName.Value & "' AND [first_name]='" & Me.cboFName.Value & "'"
If I want to filter another field based on both last_name and first_name (the field is incident_date) can I just add an AND clause to the WHERE statement and include both conditions?
For some reason it is not working. I have modified the text to match the tables
Private Sub cboFName_AfterUpdate()
Dim str As String
str = "SELECT [incident_date] FROM tblAccident_Illness" & _
" WHERE [last_name] = '" & Me.cboLName.Value & "' AND [first_name]='" & Me.cboFName.Value & "'"
Me.cboIDate.RowSourceType = "Table/Query"
Me.cboIDate.RowSource = str
Me.cboIDate.ColumnCount = 2
Me.cboIDate.Requery
End Sub
I am getting an error on all the .RowSource statements.
Ultimately what I am trying to do is to create a form of the three items where each box filters off the next and then have a command button that will open a report that will use the criteria selected in the three boxes.
str = "SELECT [incident_date] FROM tblAccident_Illness" & _
" WHERE [last_name] = '" & Me.cboLName.Value & "' AND [first_name]='" & Me.cboFName.Value & "'"
Are last_name and first_name fields in the tblAccident_Illness table, if not what is the relationship between the two tables.
For some reason it is not working. I have modified the text to match the tables
Private Sub cboFName_AfterUpdate()
Dim str As String
str = "SELECT [incident_date] FROM tblAccident_Illness" & _
" WHERE [last_name] = '" & Me.cboLName.Value & "' AND [first_name]='" & Me.cboFName.Value & "'"
Me.cboIDate.RowSourceType = "Table/Query"
Me.cboIDate.RowSource = str
Me.cboIDate.ColumnCount = 2
Me.cboIDate.Requery
End Sub
I am getting an error on all the .RowSource statements.
Ultimately what I am trying to do is to create a form of the three items where each box filters off the next and then have a command button that will open a report that will use the criteria selected in the three boxes.
last_name and first_name are in tblAccident_Illness.
Also how do I get the information on the form to be the record selected for a report that I already have? The report is based on a query called
Accident_report
The fields last_name first_name and incident_date are also available in the query. Should the selection form use these fields and then I could put a command button to run or print the report. Will I need to specify that I want the selected record to be the only one in the report of will that be the default if I use the query that runs the report to generate the form?
Also I have a report that uses a crosstab query called bodycrosstab. This cross tab counts the number of incidents for each body part for each month. The report and query are working fine but I need a way that each time the report is run it asks which year should be used (and then filters the data in the report for that year. This would also need to be made availabile in the header of the report so if I selected 2005 then the header of the report would be Body Parts 2005.
Thanks for your help. After these two things I will be done.
I was able to solve the problem with the report and the form acting as a filter. The only question I still have is the one below
Also I have a report that uses a crosstab query called bodycrosstab. This cross tab counts the number of incidents for each body part for each month. The report and query are working fine but I need a way that each time the report is run it asks which year should be used (and then filters the data in the report for that year. This would also need to be made availabile in the header of the report so if I selected 2005 then the header of the report would be Body Parts 2005.
It depends where you are opening the report from. I would suggest that if you are using a command button on a form you add a combobox (cboYear) above it with a list of Years (You could just design a lookup table or set a query to get the year field from the query grouped on year field).
Ask the user to select a year before running the report and in the On Click event of the button (cmdPrint) put the following code. -
Private Sub cmdPrint_OnClick()
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
If IsNull(Me.cboYear) Then
-
Msgbox "You must select a year", vbOkOnly
-
Exit Sub
-
Else
-
stDocName = "Name of Crosstab Query Report"
-
stLinkCriteria = "[Year]=" & Me.cboYear
-
DoCmd.OpenReport stDocName, , , stLinkCriteria
-
End Sub
-
Put a textbox control on the Report next to the Header Label and set the source to
=[Forms]![FormName]![cboYear]
I was able to solve the problem with the report and the form acting as a filter. The only question I still have is the one below
Also I have a report that uses a crosstab query called bodycrosstab. This cross tab counts the number of incidents for each body part for each month. The report and query are working fine but I need a way that each time the report is run it asks which year should be used (and then filters the data in the report for that year. This would also need to be made availabile in the header of the report so if I selected 2005 then the header of the report would be Body Parts 2005.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dalan |
last post by:
Okay, I have worked on this and then some, but cannot seem to crack
it. So if someone can straighten my code out, or suggest a new
approach, then I'm all ears.
Here goes: I have two tables - one...
|
by: Jason |
last post by:
I am trying to filter records in a primary form based on records in
related tables. The data in the related tables is being displayed in
the primary form
through subforms. To be more specific, I...
|
by: Sean |
last post by:
Greetings all,
I am attempting to make a form that will filter through several tables
that
(I believe) have refretial integrity. I am pulling data from several
tables into the form and i would...
|
by: Scott Loupin |
last post by:
I've got two databases with similar data in them (WestSide and EastSide).
I've set up two identical reports that is filtered by date and the client
name. I'm using one form to do the filtering.
...
|
by: MLH |
last post by:
I have a form (xxxxxxxxxxxxxx) with a combo-box control
(yyyyyyyyyyyyyy). The rowsource property for that combo box is as
follows:
SELECT DISTINCTROW .,
. FROM ;
The SQL for qryVehicleList...
|
by: hackerslacker |
last post by:
I have an ordering form that use two combo boxes to filter down the
records of a Products table. This worked fine with the after_Update of
the first filtering the records and creating the...
|
by: Dev1 |
last post by:
All-
I'm new to this forum and i've been working with acces for about 2 days now. I have a form in which I have two combo boxes and depending on what is selected on the first dropdown the second...
|
by: novoselent |
last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong...
Using Access 2003
I have a form that lists vehicle service...
|
by: flymo |
last post by:
Hello All,
I've bee trying out access 2007 and have a weird issue and would like
to see if I'm issing something really basic.
I have a form based on a query, I create a combo to look for records...
|
by: RHooper |
last post by:
Hi,
I'm new to Access, so I apologize if this question is trivial.
I am trying to set-up a quick filter for users to define on a form bound to a table. I have a combo box called...
|
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...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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...
| |