Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add a where clause to expression builder - Easy fix?

Posted on 2008-10-30
2
Medium Priority
?
1,049 Views
Last Modified: 2013-11-28
Hello,

This should be a quick fix - but access is driving me nuts.  

In the simplest of terms: I have a two tables, A and B.  When a user clicks a particular field in table A, they are passed through to table B.  Table B contains a field called "NameField" which relates to a username.  The ID of this user is also passed to table B, and this appears in the NameField.

What I want to do, is run an epxression within the NameField similar to:

NameField = select username from users where userID = tableB.NameField....

Easy right?  I've tried creating macros, expressions, yadda yadda, and nothing.  This baffles me as it is the corner-stone of all forms: passing ID's and then looking up the rest of the info based on the ID.
 
0
Comment
Question by:south_paw
2 Comments
 
LVL 6

Expert Comment

by:carazuul
ID: 22846401
Hi south paw,
When you run the OpenForm action from Form A you can include a where clause to filter the results of the new form. In your case, adding a NameField = [Selected Name]. The code below shows an example of this.
Regards,
carazuul

Private Sub OpenNewFormButton_Click()
    
    Dim strForm As String, strFilter As String
    
    strForm = "FormB"
    strFilter = "NameField = '[userID]'"
    
    DoCmd.OpenForm strForm, , , strFilter
    
End Sub

Open in new window

0
 

Accepted Solution

by:
south_paw earned 0 total points
ID: 22846719
Hi,

Thanks but I need to do it for the particular field only.  I am already filtering data using something similar to the above, but table "users" is not the same thing as TableB.

Hope that helps.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question