INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help with WHERE clause

Help with WHERE clause

(OP)
Hello I have managed to confuse myself more than normal.

I have an Accounts Form which populates on open from a DOA recordet that I create from an external table.

I have all of that working fine. At the moment I am soing a SELECT * and this works fine.

What I actually want to do is exclude certain records.

For example there is a TYPE field in the table and I want to select everything except records with a TYPE of "Deposit Paid"

My current working code is:

CODE -->

Dim strSQL As String
Dim rs As DAO.Recordset

  strSQL = "SELECT * FROM " & Me.txt_Gem_Account_No.Value
  strSQL = strSQL & " ORDER BY date desc"
      
  Set rs = db.OpenRecordset(strSQL) 

I have tried all sort of efforts such as:

CODE -->

Dim strSQL As String
Dim rs As DAO.Recordset
    
  strSQL = "SELECT * FROM " & Me.txt_Gem_Account_No.Value &, _
            "WHERE [type] <> 'rent paid"
  strSQL = strSQL & " ORDER BY date desc"
      
  Set rs = db.OpenRecordset(strSQL) 

I could do with some help. Many thanks Mark

RE: Help with WHERE clause

> everything except records with a TYPE of "Deposit Paid"
> "WHERE [type] <> 'rent paid"

strSQL = "SELECT * FROM " & Me.txt_Gem_Account_No.Value & _
" WHERE UCase([type]) <> UCase('rent paid')"
strSQL = strSQL & " ORDER BY date desc"

or

strSQL = "SELECT * FROM " & Me.txt_Gem_Account_No.Value & _
" WHERE UCase([type]) NOT IN UCase('Deposit Paid')"
strSQL = strSQL & " ORDER BY date desc"


Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Help with WHERE clause

(OP)
This is working thank you.....

CODE -->

strSQL = "SELECT * FROM " & Me.txt_Gem_Account_No.Value & _
" WHERE UCase([type]) <> UCase('rent paid')"
strSQL = strSQL & " ORDER BY date desc" 

If I wanted to exclude other items can you demonstate how to do that..

ie. If I wanted to exclude 'rent paid' 'deposit paid' and 'fee paid'

Many thanks Mark

RE: Help with WHERE clause

CODE

WHERE UCase([type]) NOT IN ('RENT PAID','SOME OTHER TYPE')" 
...etc.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Help with WHERE clause

(OP)
That's great - thank you all :)

RE: Help with WHERE clause

One would hope you would have a small look-up table, something like:

Money_Paid
MID MoneyDesc
1   rent paid
2   deposit paid
3   fee paid
...
 
and in any other table(s) you would keep just the PK (as a FK) from that table, and NOT the description of it. So your SQL would be something like:

WHERE MoneyID NOT IN (1, 2, 3)

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close