#ERROR on =IIf(DCount [...] with Alphanumeric field - ms-access

I am using a DCOUNT function to look at a table in access and see if a record exists - if it does then return a yes value.
=IIf(DCount("*","COMMENTS","[PROJECTID] = " & [PROJECTID])>0,"YES","")
This works great if my ProjectID is all numeric values - I only get #Error on the alphanumeric values.
I know that I have to make the ProjectID criteria a string but am having trouble placing the quotes.

First, break out the DCount piece and work on that by itself.
It sounds like your COMMENTS.PROJECTID field is text datatype, so add quotes before and after the value you concatenate into the third DCount argument (Criteria):
DCount("*", "COMMENTS", "[PROJECTID] = '" & [PROJECTID] & "'")
After you have that piece working correctly, add it into your IIf() function.

Related

MS access Query with in and parameter

I need to create a query in MS access where the parameter is a list (given by me).
This works In ("2209487";"2102669";"2727930";"3727550"), but if I try to put a parameter inside the "IN" like this: In ([NUM]) It doesn't return a result!
I write 2209487";"2102669";"2727930";"3727550 when the parameter window appears.
PS: my laptop is in European Portuguese so I use the ";"
You can't use a "list" or "multiple" values for this. But you CAN do this in the where clause of hte form (or report).
First, remove any paramters for the form/report. You want to be able to open/launch the form/report WITHOUT any prompts from the query. In fact, what follows will even work if you based the form/report directly on the table.
So, you can do this:
dim strInvoices as string
strInvoices = InputBox("Enter invoice numbers ',' between each")
dim strWhere as string
strWhere = "InvoiceNumber in (" & strInvoices & ")"
docmd.OpenReport "frmInvoices",,,strWhere
So, you can provide a list as per above and use the "in"
the IN clause is this
InvoiceNumber in (234,433,555)
So, you can pass the conditions as a "where" clause to a open form or report.
Thanks to all!!!!
i've redone the query and logic of the database) in another way.

SSRS not recognizing dataset in expression for barcode

Whenever I use this code
=IIf(JPCI_RPT_ReceiptStatusHeaderBLW.RECEIPT_ID_TYPE = "Trailer ID",
Code.StringToBarcode({JPCI_RPT_ReceiptStatusHeaderBLW.trailer_id}),
Code.StringToBarcode({JPCI_RPT_ReceiptStatusHeaderBLW.receipt_id_type}) & chr(10) &
Code.StringToBarcode({JPCI_RPT_ReceiptStatusDetailsBLW.item})
I get the following error...
Name 'JPCI_RPT_ReceiptStatusHeaderBLW' is not declared.
It's checking for dataset right? If not, how do I declare it?
The expression is looking for a field name and you're converting something like Crystal Reports to SSRS. In SSRS you refer to a field value with Fields!FieldName.Value.
Assumeing that you have a dataset with necessary fields, your expression would be something like:
=IIF(Fields!RECEIPT_ID_TYPE.Value = "Trailer ID",
Code.StringToBarcode(Fields!trailer_id.Value),
Code.StringToBarcode(Fields!receipt_id_type.Value) & chr(10) &
Code.StringToBarcode(Fields!item.Value) )
You had missed a closing parenthesis as well, but the error check didn't get that far.

How to evaluate an expression in Access like evaluating a formula in excel

Is there a way to evaluate an expression in Access like we can evaluate formulae in Excel? My Dlookup keeps resulting in the number two and I can't figure out where the hang up is.
=Nz(DLookUp("[RemanChangePoint]![ID]","[RemanChangePoint]","[NewPartNum] Like '*" & [LegacyPN1] & "*' Or [NewPartNum] Like '*" & [LegacyPN2] & "*'"),"")
There's 10 more LegacyPNs and I am expecting to get either the ID of the record that has the LegacyPN or a blank. Before, instead of doing it as above, I was doing:
Like & Chr(34) & "*" & [LegacyPN#] & "*" & Chr(34) & " Or..."
It would result in 2 every time. But now with the shortened version, it's resulting in blanks every time, even though there are records with the part number.
I have a similar expression on a different form, but only one LegacyPN to use as the lookup so it works. I assume that the problem is the numerous Or statements, but it doesn't make sense to me why it's not working, thus the desire for an expression evaluator like Excel has.
Or (and this may be a little uncouth to ask a slightly different question)
Is there a way to use an attachment's file name as the criteria for Dlookup? That may prove more effective than going by LegacyPN, I just can't figure it out via the expression builder.
Your first DLookup where clause is referring to fields on the current form since the double quotes cause the expression to break out of the where clause and into the scope of the ControlSource.
This means something like the following will be passed into the DLookup function because the [LegacyPN] portions of the expression are evaluated in the context of the form, before DLookup is called:
[NewPartNum] Like '*1*' Or [NewPartNum] Like '*2*'
...where 1 and 2 are values of [LegacyPN1] and [LegacyPN2] on the current form.
If you want the [LegacyPN] fields in the DLookup where clause to refer to the [RemanChangePoint] table being queried by the DLookup, then you need to fix your quotes:
=Nz(DLookUp("[RemanChangePoint]![ID]","[RemanChangePoint]", "[NewPartNum] Like '*' & [LegacyPN1] & '*' Or [NewPartNum] Like '*' & [LegacyPN2] & '*'"),"")
Your second syntax should have also worked because the Chr(34) added a double quote resulting in this final string being passed to the DLookup function in the where clause:
Like & "*" & [LegacyPN] & "*" & " Or..."
In which the [LegacyPN] field refers to the table within the DLookup query, not the current form. So I'm not sure why that didn't work. Note: single quotes or double quotes work okay in this context but not a mixture.
Double quotes get tricky within arguments of functions within a CountrolSource property (and other places).

How to do a DLOOKUP

I am trying to do a DLOOKUP but not sure where I am going wrong.
I have a table header of the date, in my example: 04/04/16
I have a table called tblMasterLeagueAvailability
I have a textbox called text2 with the individuals name in it
=DLookUp("04/04/16","tblMasterLeagueAvailability","[Name] = [Text2] ")
The formula above is not working.
I want it to lookup the table header 04/04/16 in tblMasterLeagueAvailability and show the results for the persons name in text2
Thank you in advance
The textbox reference must be outside the string. Try something like
=DLookUp("04/04/16","tblMasterLeagueAvailability",
"[Name] = '" & Replace(Forms!myForm![Text2], "'", "''") & "'")
You need the single quotes ' for filtering text fields.
The Replace() is there to prevent an error when [Text2] contains a ' itself.
Note: a column name "04/04/16" indicates a problematic table design.

Using variables in a filter string

I have a subform that returns data from a table. However I want to further filter this data by using the filter property.
I have a group of radio buttons, combo boxes and a case statement which sets the variables I want to use to the correct values depending on the radio button selection
My code for filling the variables works perfectly but I cannot use vba to set the filter unless I manually type the string that I want.
I assume that my issue is that my filter string is syntactically incorrect but I am unsure of how. Probably something to do with text delimiters.
Forms![frmPendingActions]![qryPendingAction subform].Form.Filter = Filterby = FilterCrit
Forms![frmPendingActions]![qryPendingAction subform].Form.FilterOn = True
Assume for this question that Filterby=[Reporter] and FilterCrit= Fake Name
Yes I think the problem is to do with text delimiters. The code should look similar to the following:
Forms![frmPendingActions]![qryPendingAction subform].Form.Filter = "[Reporter] ='" & FilterCrit & "'"
The filter should be built exactly the same as a where clause without the word where. If the column you are filtering by has a text datatype then the criteria needs to be enclosed in single or double quotes. If the column is a date datatype then it needs to be enclosed in #. If the column is a number datatype then it does not need to be enclosed.
If you do not always wish to filter by the Reporter column then you can build a string using if statements or select case statements and then apply that string to the form filter.
For example:
If [somecondition] Then
strFilter="[Reporter]='" & FilterCrit & "'"
Else
strFilter="[ID]=" & 0
End If
Forms![frmPendingActions]![qryPendingAction subform].Form.Filter = strFilter
I hope this helps.