 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 4th, 2006, 04:58 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 4th, 2006, 05:18 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

March 4th, 2006, 08:46 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In a query
|
|

March 6th, 2006, 01:20 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

March 6th, 2006, 07:34 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

March 6th, 2006, 10:15 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

March 6th, 2006, 10:39 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 6th, 2006, 11:28 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

March 7th, 2006, 12:43 AM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 7th, 2006, 12:51 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|
 |