473,385 Members | 1,320 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,385 software developers and data experts.

filter a table based on a field in another table...

13
this is crazy, why can't i get this to work?!!

i have a complex DB with many tables, but the ones that count here are:

a linked SQL table with many records and a field called userEmail

locally I have a table called userDetails, with a field called useremail

so i built this query which limits my view to only my records:

SELECT *
FROM dbo_TrackerMainData, userDetails
WHERE (((dbo_TrackerMainData.userEmail)=[userDetails]![useremail]));

when i run this query manually it returns only 'my' records. which is perfect

but when i try to use this query on a form, it doesn't work at all - instead of filtering based on the fields contents, its prompting me to type in data for

[userDetails]![useremail]


WHY!!


so, i tried something else:

a function to do the same work -

Public Function userFilter()
Dim useremail As String

useremail = DLookup("[useremail]", "userdetails", Not Null)

Dim sql1 As String
Dim sql2 As String
Dim sql3 As String
Dim strSQL As String

sql1 = "SELECT * "
sql2 = "FROM dbo_TrackerMainData "
sql3 = "WHERE userEmail='" & useremail & "'"
strSQL = sql1 & sql2 & sql3
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL

End Function


that doesn't work either for lots of odd reasons.....


any ideas?????

I'm going mad here with this - its surely a simple thing to filter a table with data from another?!

thanks for any help !
Jul 28 '07 #1
3 5102
puppydogbuddy
1,923 Expert 1GB
this is crazy, why can't i get this to work?!!

i have a complex DB with many tables, but the ones that count here are:

a linked SQL table with many records and a field called userEmail

locally I have a table called userDetails, with a field called useremail

so i built this query which limits my view to only my records:

SELECT *
FROM dbo_TrackerMainData, userDetails
WHERE (((dbo_TrackerMainData.userEmail)=[userDetails]![useremail]));

when i run this query manually it returns only 'my' records. which is perfect

but when i try to use this query on a form, it doesn't work at all - instead of filtering based on the fields contents, its prompting me to type in data for

[userDetails]![useremail]


WHY!!


so, i tried something else:

a function to do the same work -

Public Function userFilter()
Dim useremail As String

useremail = DLookup("[useremail]", "userdetails", Not Null)

Dim sql1 As String
Dim sql2 As String
Dim sql3 As String
Dim strSQL As String

sql1 = "SELECT * "
sql2 = "FROM dbo_TrackerMainData "
sql3 = "WHERE userEmail='" & useremail & "'"
strSQL = sql1 & sql2 & sql3
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL

End Function


that doesn't work either for lots of odd reasons.....


any ideas?????

I'm going mad here with this - its surely a simple thing to filter a table with data from another?!

thanks for any help !
Hmmm...query works, but not with form....
1. Make sure form and controls are bound to the query via the record source and control source properties.
2. Verify that form's data entry property set to no, otherwise form will open in new record mode (blank).
3. Verify that allow edits,add, and deletes properties of the form are set to yes.
Jul 28 '07 #2
maxamis4
295 Expert 100+
what you need to do is build the query. When you build it and reference another table you have inlcude the table name. for example you would have to use table1![Your table variable] The reason its prompting you is because it doesn't know where to reference your value.

let me know if you need any other help
Jul 28 '07 #3
webcat
13
thanks - but i have tried all these things and it doesn't work :(


when i run the query by double clicking it, it returns the records it should be returning, but when i run the query from a form, it asks for 'enter parameter value' with the name of the box as my query

userDetails.useremail

instead of taking that value from the table

why would this happen ???

thanks for any help.
Jul 31 '07 #4

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

Similar topics

8
by: swilson513 | last post by:
In Access97 I was able to have an advance filter on a form that had a Like statement so when you applied the filter EACH time it would asked for the criteria. In 2000 the same filter doesn't asked...
11
by: Bob | last post by:
I am in the process of upgrading an Access database to SQL Server (and climbing that learning curve!). The wizard happily upgraded all the tables and I can link to them OK using ODBC. The...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
0
by: Josetta | last post by:
This is for informational purposes...I had a problem and I thought it might help others in a similar situation. I hope someone, someday, finds this idea useful. I've garnered so much knowledge...
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: 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...
0
isladogs
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...
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:
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...
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: 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...

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.