Off-topic Talk Where overpaid, underworked S2000 owners waste the worst part of their days before the drive home. This forum is for general chit chat and discussions not covered by the other off-topic forums.

access wizards...

Thread Tools
 
Old Oct 28, 2004 | 12:40 PM
  #1  
steven975's Avatar
Thread Starter
Registered User
 
Joined: May 2004
Posts: 5,094
Likes: 6
From: Vienna, VA
Default access wizards...

OK, here's what I need to do.

I have a query, and I have a form. The form has 3 fields, each tied to a field in the query. I want to have the query output results based on what is typed into the 3 text boxes on the form.

I know to put the form's textbox value in the criteria field, but the problem is I have 3 fields, not one. I won't get that complex here because I don't need to.

Here's what I need: If the form's text box is blank, I want EVERY value to show up in the query, and if there is a specific value in the text box, I want the query to show those. I know how to do the latter, it is the former causing me trouble. I can't quite figure out how to code the wildcard.

Basically, IIF([form]![textbox] is null, ***output every value***,[form]![textbox])

This is what I'm typing into the criteria section in the query, but I cannot figure out how to code the wildcard. I've tried "*", "%", like "*" in the "***output every value***" part of the code.

Any takers on this one????
Reply
Old Oct 28, 2004 | 03:57 PM
  #2  
jbbrann's Avatar
Registered User
 
Joined: Sep 2001
Posts: 125
Likes: 0
From: Conway
Default

Do you know the theoretical min and max values of the values you are evaluating against? If so, assume you are returning the values in a column named Item1 (an integer between 1 and 1000) depending on what is entered in txtItem1 on frmMain:


[SQL]SELECT *
FROM tblTemp WHERE tblTemp.Item1 >= IIf([Forms]![frmMain].[txtItem1] Is Null,0,[Forms]![frmMain].[txtItem1]) AND tblTemp.Item1 <= IIf([Forms]![frmMain].[txtItem1] Is Null,9999,[Forms]![frmMain].[txtItem1])[/SQL]

The same can be done if you're selecting from a text field by using ' ' and 'ZZZZZZZZZZZZZZZZZZZZZ......' instead of 0 and 9999.
Reply
Old Oct 28, 2004 | 06:54 PM
  #3  
steven975's Avatar
Thread Starter
Registered User
 
Joined: May 2004
Posts: 5,094
Likes: 6
From: Vienna, VA
Default

the values represent department numbers, a 4 digit number I would probably consider a text field. Further complicating things is I want to search on two more fields, too. I hope access can do that.

I did notict that I didn't put WHERE in the expression and instead put GROUP BY I think. I hope that's it. Basically, all I want to do is return EVERY value in the query if the text box in the form is empty. The rest I can do, but it seems the wildcard coding is eluding me.

I think what you did may help, but I won't know until Monday. Seems with your code if the item is null, it will return every possible value anyway. Seems better than trying a wildcard, which hasn't worked for me.

Hope it works.
Any other Access/Database experts out there? These skills are EXTREMELY rare in my company and TRUE database experts outside of consulting firms are rare, too. Oh well, it basically helps to make sure I stay employed because my company is very grateful I know how to do this stuff. I work in finance, by the way.
Reply
Old Oct 28, 2004 | 07:34 PM
  #4  
steven975's Avatar
Thread Starter
Registered User
 
Joined: May 2004
Posts: 5,094
Likes: 6
From: Vienna, VA
Default

I just made a small dbase here at home to test the concept, and it worked. Thanks!

Here's the code I wrote:
Between IIf([Forms]![Form1]![Text0] Is Null,"A",[Forms]![Form1]![Text0]) And IIf([Forms]![Form1]![Text0] Is Null,"Z",[Forms]![Form1]![Text0])
Reply
Old Oct 29, 2004 | 12:28 PM
  #5  
yogi's Avatar
Registered User
Gold Member (Premium)
20 Year Member
 
Joined: Oct 2000
Posts: 2,108
Likes: 0
From: Seattle, WA
Default

Ewww, Access code is fugly!
Reply
Old Oct 30, 2004 | 11:45 AM
  #6  
steven975's Avatar
Thread Starter
Registered User
 
Joined: May 2004
Posts: 5,094
Likes: 6
From: Vienna, VA
Default

eh, it looks impressive, but it is much easier to write than it looks. That's actually a SIMPLE one. You should see some of my others that are 7 lines long
Reply
Old Oct 30, 2004 | 12:17 PM
  #7  
yogi's Avatar
Registered User
Gold Member (Premium)
20 Year Member
 
Joined: Oct 2000
Posts: 2,108
Likes: 0
From: Seattle, WA
Default

Wait a sec, you could've done all of that in SQL, couldn't you? I forget what SQL functions Access supports though.
Reply
Old Oct 30, 2004 | 02:29 PM
  #8  
no_really's Avatar
Banned
 
Joined: Dec 2003
Posts: 3,319
Likes: 0
From: City
Default

He IS using SQL statements to do this. That is the problem. If he was using non-bound controls in a form, he would be able to dynamically build his query without resorting to making SQL perform his logic. That would be easy. Trying to put business logic in SQL code is hard and ugly because it doesn't belong there.
Reply
Old Oct 30, 2004 | 02:51 PM
  #9  
yogi's Avatar
Registered User
Gold Member (Premium)
20 Year Member
 
Joined: Oct 2000
Posts: 2,108
Likes: 0
From: Seattle, WA
Default

IIf([Forms]![Form1]![Text0] Is Null,"A",[Forms]![Form1]![Text0]) And IIf([Forms]![Form1]![Text0] Is Null,"Z",[Forms]![Form1]![Text0]) is not SQL But yea, I saw the earlier post, it's inside a SQL statement. A quick VB function (procedure? whatever the hell VB calls it) would do the trick. Death to Access!
Reply
Old Oct 30, 2004 | 09:46 PM
  #10  
no_really's Avatar
Banned
 
Joined: Dec 2003
Posts: 3,319
Likes: 0
From: City
Default

sorry, iif is a VB function. There are different kinds of SQL in use, like T-SQL, ANSI92, etc. Just because you cannot use one statement on every "SQL"-processing server doesn't make one SQL and the rest "not" SQL.

Access is actually pretty powerful, and far better than anything from Oracle, Sybase, Sun, or anyone else, for what it can do. The issue is people try to do things outside the intended scope of the methods they use. Access is a Rapid Application Development tool, and as such, it works very well, for more than just database software. It has limitations, but most often, people's knowledge is the limiting factor, not Access.
Reply



All times are GMT -8. The time now is 08:22 PM.