Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 4th, 2006, 04:58 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query with IIF

Basically what I am trying to do is replace the evaluation part of the IIF with a Text String.

Normal SQL that works.
PriceUSDCode: IIf([Invoicebody].[code]="536" Or [InvoiceBody].[code]="537",([PriceUSD]*0.8),[PriceUSD])


IIF(Text String From Text Box, apply discount, no discount)

I have tried these strings in my text box:
[code]="536" or [code]="537"
[InvoiceBody].[code]="536" or [InvoiceBody].[code]="537"
Neither one works

This allows my operators to change this string and apply the discounts necessary. My idea is in the end, use a drop down box with the various different discount strings. Pick and automatically its applied to the printed report.

Thanks for your help.


Reply With Quote
  #2 (permalink)  
Old March 4th, 2006, 05:18 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Are you trying to use this in a query, or are you just wanting to display the amount in a text box on your form?

Mike
EchoVue.com
Reply With Quote
  #3 (permalink)  
Old March 4th, 2006, 08:46 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In a query

Reply With Quote
  #4 (permalink)  
Old March 6th, 2006, 01:20 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Alright - sorry this took a while...

In your query - assume that the name of the form you want to reference is frmMyForm and the field that you want to reference is called txtMyField.

Set your parameter to

Forms![frmMyForm]![txtCode]

Hope that helps,

Mike

Mike
EchoVue.com
Reply With Quote
  #5 (permalink)  
Old March 6th, 2006, 07:34 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike, I have tried that in my query

PriceUSDCode: IIf(forms![menu]![PriceDiscountString],([PriceUSD]*0.8),[PriceUSD])
What happens is the query applies the discount to every record.

My text box hold this string:
[code]="536" or [code]="537"
Is this where i'm going wrong? is it that i am missing something here?



Reply With Quote
  #6 (permalink)  
Old March 6th, 2006, 10:15 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

You're half way there, now add the code field to the query, and use the same format of code to restrict it to those codes. If you don't want it showing, just uncheck the show box.

That should do it.

Mike

Mike
EchoVue.com
Reply With Quote
  #7 (permalink)  
Old March 6th, 2006, 10:39 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike,
Sorry to say but it does not work. Here is my complete SQL.

SELECT InvoiceBody.Code, IIf([forms]![menu]![PriceDiscount],([PriceUSD]*0.8),[PriceUSD]) AS PriceUSDCode, [sorprifix] & "-" & [SOR] & "-" & [SORext] AS SORNo, Invoices.DateIssueSOR, Invoices.InvPaid, InvoiceBody.QTY, Invoices.invwotype, Invoices.WorkOrderNo, Invoices.CustNo, Invoices.Exchange, Customers.NAME, InvoiceBody.InvoiceNumber, InvoiceBody.PriceUSD, InvoiceBody.CostCenter, Invoices.DollarInvoice, Invoices.SOR, Round([invoicebody].[qty]*[PriceUSDCode],2) AS ExtUSD, IIf([Invoices].[DollarInvoice]="1",Round([PriceUSDCode]*[forms].[menu].[TipoDeCambioAnt2],2),[PriceUSDCode]) AS PricePesos, Round([PricePesos]*[invoicebody].[QTY],2) AS ExtPesos, IIf(IsNull([code])=True,"",[code] & "-" & [CostCenter]) AS codigo, IIf([dollarInvoice]="1",[extUSD],0) AS USD, IIf([dollarInvoice]="2",[extPesos],0) AS MN
FROM (Invoices INNER JOIN Customers ON Invoices.CustNo = Customers.CustomerNum) INNER JOIN InvoiceBody ON Invoices.WorkOrderNo = InvoiceBody.InvoiceNumber
WHERE (((Invoices.DateIssueSOR)<=[forms]![menu]![AntigDate2]) AND ((Invoices.InvPaid)="1") AND ((InvoiceBody.QTY) Is Not Null) AND ((Invoices.invwotype)="WO"))
ORDER BY InvoiceBody.Code;

I sure appriciate your help. I must be doing something dumb.

Reply With Quote
  #8 (permalink)  
Old March 6th, 2006, 11:28 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Check out where I put the ###'s and then I also removed the =true from the statement near the WHERE clause.

Try that and then we can take it from there.

SELECT InvoiceBody.Code, IIf([forms]![menu]![PriceDiscount]=###,([PriceUSD]*0.8),[PriceUSD]) AS PriceUSDCode, [sorprifix] & "-" & [SOR] & "-" & [SORext] AS SORNo, Invoices.DateIssueSOR, Invoices.InvPaid, InvoiceBody.QTY, Invoices.invwotype, Invoices.WorkOrderNo, Invoices.CustNo, Invoices.Exchange, Customers.NAME, InvoiceBody.InvoiceNumber, InvoiceBody.PriceUSD, InvoiceBody.CostCenter, Invoices.DollarInvoice, Invoices.SOR, Round([invoicebody].[qty]*[PriceUSDCode],2) AS ExtUSD, IIf([Invoices].[DollarInvoice]="1",Round([PriceUSDCode]*[forms].[menu].[TipoDeCambioAnt2],2),[PriceUSDCode]) AS PricePesos, Round([PricePesos]*[invoicebody].[QTY],2) AS ExtPesos, IIf(IsNull([code]),"",[code] & "-" & [CostCenter]) AS codigo, IIf([dollarInvoice]="1",[extUSD],0) AS USD, IIf([dollarInvoice]="2",[extPesos],0) AS MN
FROM (Invoices INNER JOIN Customers ON Invoices.CustNo = Customers.CustomerNum) INNER JOIN InvoiceBody ON Invoices.WorkOrderNo = InvoiceBody.InvoiceNumber
WHERE (((Invoices.DateIssueSOR)<=[forms]![menu]![AntigDate2]) AND ((Invoices.InvPaid)="1") AND ((InvoiceBody.QTY) Is Not Null) AND ((Invoices.invwotype)="WO"))
ORDER BY InvoiceBody.Code;


Mike
EchoVue.com
Reply With Quote
  #9 (permalink)  
Old March 7th, 2006, 12:43 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Once again, thanks for your help

I may be wrong or just dumb but, I think we are not on the same page. My objective is not to have any hard coded conditions in the IIF statement other than the text box reference. You indicated by your ### that I put something like =”[code]=537”, if a match with my text box then apply.

What I am looking for, and may not be possible is, I hope this is explanatory,
iif(Text Box Reference with conditions, True, False)
This will allow me to create different conditions in the text box, the operator would pick from a drop down and the condition would be applied in the query. If any part of the condition is hard coded it can’t be changed by the operator.

Options may be
[code]=”537”
[code]=”501”
[Code]=”501” or [Code]=”502”
What ever is in the text box becomes the only condition for the IIF statement.
Sorry for being so long winded but I have been stuck with this for a week and I’m about ready to give up.



Reply With Quote
  #10 (permalink)  
Old March 7th, 2006, 12:51 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Nothing like staring at a problem for a whole week to make to want to hang yourself!! Just kidding - don't do it.

The ### just mean there needs to be something there. In this case, I think you could just replace it with [code]. With an IIF or or selection type function, there has to be a comparison, otherwise it will always return true. Give that a whirl, and I think that you may have it.

Mike

Mike
EchoVue.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IIf umeshtheone Beginning VB 6 3 June 21st, 2007 12:24 AM
Nested Query with an iif statment Corey Access 7 October 17th, 2005 04:40 PM
Nested Query with an iif statment part 2 Corey Access 1 October 17th, 2005 12:47 PM
IIF in a query for a logical jgsteel VB How-To 1 December 28th, 2004 04:45 PM



All times are GMT -4. The time now is 12:40 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.