DLookUp not working properly in Microsoft Access - ms-access

Trying to pull the value in the Query to populate Form Field, not working with what I've tried.
Table 1: Quote Data
Fields: Quote #, Part #, CNC Hours
Table 2: Rate Chart
Fields: Rate Type, Cost ($)
Query 1: Cost of CNC
Fields: Quote #, Part #, CNC Hours, Parts Per Mag, Rate Type (Criteria: "3D Shop"), Cost ($)
Expression: Cost of CNC= [CNC Hours]*[Cost ($)]/[Parts Per Mag]
Main Form: Generate Quotes
SubForm: Quote Data Subform
Field Box: CNC $
Control Source: =DLookUp("[Cost of CNC]", "[Cost of CNC]", "[Part #]=" & [Forms]![Cost of CNC Subform]![Part #])
With the above Control Source I keep getting #Name? in the field text box CNC $.
I've also tried:
=DLookUp("[Cost of CNC]", "[Cost of CNC]", "[Part #] = " & [Part #]) but I get #Error.
What am I doing wrong?
I want the value in Cost of CNC (associated with the proper Part #) to populate Form Field: CNC $.

I got the following to work:
=DLookUp("[Cost of CNC]", "[Cost of CNC]", "[Part #]='"&[Part #]& "'")

Related

SSRS Report Shows #Error When Converting Number to Currency

I am trying to get the report to show the purchase price which the user enters in a parameter. If the user doesn't enter anything it will say "Undisclosed" otherwise I want it to show the purchase price as currency. I have tried the following:
=IIF(Parameters!PurchasePrice.Value = "", "Undisclosed", Cstr(Format(Parameters!PurchasePrice.Value, "C")))
=IIF(Parameters!PurchasePrice.Value = "", "Undisclosed", Format(Parameters!PurchasePrice.Value, "C"))
=IIF(Parameters!PurchasePrice.Value = "", "Undiscloded", FormatCurrency(Parameters!PurchasePrice.Value,0))
=IIF(Parameters!PurchasePrice.Value = "", "Undiscloded", FormatNumber(Parameters!PurchasePrice.Value,0))
I can get "Undisclosed" to appear but every time I enter a number it shows #Error
You can try the following solution:
=IIF(IsNumeric(Parameters!PurchasePrice.Value), Format(Val(Parameters!PurchasePrice.Value), "C"), "Undisclosed")
I would approach this slightly differently. This will avoid SSRS trying to format a non numeric to a currency. IIF will evaluate both the true and false outcomes even though only one result can be true for each instance.
I would set the textbox that shows the purchase price up as follow...
Set the Value expression to be
=VAL(Parameters!PurchasePrice.Value)
This will return a zero if the parameter value is left as blank/empty string
Then set the Format property of the textbox to
$#.00;-$#.00;Undisclosed
Assuming you want $ as the currency symbol. This format string will format the number to two decimals for positive and negative numbers and prefix the $ symbol but for zero values, it will show the work "Undisclosed"

SSRS insert text when currency value ='GBP' or 'EURO' or 'USD' ect

i have been trying to work out how i can get a ssrs expression to insert text if the following currency appear in my invoices.
I would like,
if currency value = 'GBP' then show text "please pay UK BANK 000x000x00"
if currency value = 'Euro' then show text "please pay Euro BANK 000x000x00"
We have this to make the customer clear on which bank to pay into.
You can use SWITCH (similar to CASE in SQL) to display text based on the your value of the field. I have below an example with the sample you provided. Assuming your column name is "currency".
=SWITCH(
Fields!currency.value = "GBP", "please pay UK BANK 000x000x00",
Fields!currency.value = "Euro", "please pay Euro BANK 000x000x00")

Access 2016 Form Query Issue

The query grabs/obtains the criteria from a form. The problem is I have one field that is supplied in the data table that has multiple items separated by a comma. They are called Upgrade Codes:
Example: 18AAA, 8AAA, 2GAA, 1EAA
I am using Like [Forms]![Service Action Report]![Upgrade Codes] Or Like "*" & [Forms]![Service Action Report]![Upgrade Codes] & "*" in my query and it works all but also returns similar matches.
For example: 8AAA Form query search would return all records with 8AAA and also 18AAA since 8AAA is part of 18AAA this is not the desired outcome, is their a way to just get all records with the Upgrade Code supplied in the Form?
Try the following:
Like [Forms]![Service Action Report]![Upgrade Codes] Or
Like [Forms]![Service Action Report]![Upgrade Codes] & ", *" Or
Like "*, " & [Forms]![Service Action Report]![Upgrade Codes] & ", *" Or
Like "*, " & [Forms]![Service Action Report]![Upgrade Codes]
By including the * , and , * in your query it actually looks like the following for a upgrade code value like 8AAA:
Like "8AAA" Or
Like "8AAA, *" Or
Like "*, 8AAA, *" Or
Like "*, 8AAA"
The differend "or" seperated statements work like follows:
"8AAA":
Full match of 8AAA (there are no other values in the string)
"8AAA, *":
Match 8AAA only if it is the first comma seperated value in the list
"*, 8AAA, *":
Match 8AAA only if it is a middle value surounded by 2 commas
"*, 8AAA":
Match 8AAA only if it is the last value
By including the boundaries comma or beginning/end of the string you ensure that only full codes can match.

Delimiting text string based off of muliple critera instead of charector in MS Access Query

I have a field with varying strings of concatenated text that I need to delimit. I need the phrase and the count of how many times that phrase appeared into two separate fields and then repeating the same process for every additional phrase.
Example of table field text:
"some text":2; some:other NEAR text:1;
Desired Results:
[Field 1]: "Some Text", [Field 2]: 2, [Field 3]: some:other NEAR text, [Field 4] 1
The problem I am having is that when I use ":" and ";" to delimit the field using Len, Instr, InstrRev, Left, Right and Mid functions it is delimiting the "some:other NEAR text" string into "some" and "other NEAR text". Is there a way around this or should I go about this in another way? Any help is appreciated.
Is this a one-time fix of bad data to parse into discrete fields? Should show your attempted code.
Assuming every record has value in the example structure, try (x represents your concatenated data field):
Field1: Left(x, InStr(x, ":")-1)
Field2: Val(Mid(Left(x, InStr(x, ";")),InStrRev(Left(x, InStr(x, ";")),":")+1))
Field3: Mid(x, InStr(x, ";")+2, Len(Mid(x, InStr(x, ";")+2))-Len(Mid(x,InStrRev(x,":"))))
Field4: Val(Mid(x,InStrRev(x,":")+1))
Otherwise, might have to build a custom VBA function.

DLookup with Multiple Criteria

I have an Access DB that has the following tables:
• 'Legal Entity Info' with [LegEntID] and [LegEntName]
• 'Policy Info' with [PolicyID] and [PolicyCarrierName]
• 'Policy Period' with [PolicyPeriodID] and [PolicyPeriod]
• 'Retention Amounts by Legal Entity' with [RetentionID], [PolicyPeriodID], [PolicyID], [LegEntID] and [RetentionAmount]
I have a form (Retention Payment Info Form), that pulls in the [PolicyPeriodID], [PolicyID], and [LegEntID] that are connected with a specific claim. I need to pull in the correct [RetentionAmount] that corresponds to the match in the 'Retention Amounts by Legal Entity' table. All three criteria ([PolicyPeriodID], [PolicyID], and [LegEntID]) have to be TRUE in order to pull in the correct [RetentionAmount].
On this form, I have an unbound field to show the [RetentionAmount] and I’m trying to write a DLookup function to select the [RetentionAmount] based on the selections on the form. Here is what I think it should look like, however, it’s not working.
=DLookUp("[RetentionAmount]",
"Retention Amounts by Legal Entity",
"[PolicyPeriodID]='" & Forms![Retention Payment Info Form].Form.[PolicyPeriodID] &
"' AND [PolicyID]='" & Forms![Retention Payment Info Form].Form.[PolicyID] &
"' AND [LegEntID]='" & Forms![Retention Payment Info Form].Form.[LegEntID] &
"'")
Any suggestions?
.Form is only needed when working with subforms.
http://access.mvps.org/access/forms/frm0031.htm is a good reference.
(You are here: Forms!Mainform!ControlName)
Correct syntax:
=DLookUp("[RetentionAmount]",
"Retention Amounts by Legal Entity",
"[PolicyPeriodID]=" & Forms![Retention Payment Info Form]![PolicyPeriodID] &
" AND [PolicyID]=" & Forms![Retention Payment Info Form]![PolicyID] &
" AND [LegEntID]=" & Forms![Retention Payment Info Form]![LegEntID])