I'm writing a query to output to a report which will be printed and used as an internal business form. I'm having issues trying to get the date placeholders to output for records where these values are null. It's probably just easier to show the code:
IStatement: "For a period from " & Nz(FormatDateTime([DateFrom],2),"________") & " to " & Nz(FormatDateTime([DateTo],2),"________") & "inclusive at the rate of " & Nz(FormatCurrency([InclusiveRate]),"$______") & " per " & [InclusiveTimeFrame]
I'm trying to get a blank line eight spaces wide to display in the query when there is not date in the record. What the heck am I doing wrong?
FormatDateTime
will return string and never null hence your Nz isn't working. However, you could try iif(not isnull([DateFrom]), FormatDateTime([DateFrom],2),"________")
or write your custom function for validating the date field.
Related
I am attempting to add a running count to a time series table by API number. The running count would be an indicator of what production month a given well is in.
Table: MonthlyProd
Fields: API, YEAR, MONTH, LIQUID
Desired Field: RunningCount
Desired Result
I cannot quite figure out a Dcount expression in MS Access.
Edit* Current progress is as follows. Using the following Access query
ProdMonth: DCount("API","Monthly Production","API=" & [API] & " AND (YEAR<" & [YEAR] & " OR (YEAR=" & [YEAR] & " AND MONTHNUMBER<=" & [MONTHNUMBER] & "))")
Yields the following results
Running Total Not quite there
I assume I am off in the logic statement somewhere?
Try something like this:
DCOUNT("API","MonthlyProd","API=" & API & " AND (YEAR<" & YEAR & " OR (YEAR=" & YEAR & " AND MONTH<" & MONTH & "))")
This assumes API, MONTH, YEAR are numerical.
I found a solution.
I needed to format the Month and Year into a date serial number in one field.
The correct DCount function was as follows:
ProdMonth: DCount("API","MonthlyFix","API=" & [API] & " AND DateSer<=" & [DateSer])
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).
I know this is probably a simple thing I'm missing, but I'm hoping you all can help. I'm trying to add a textbox to my form that allows users to type in search criteria and have the query filter the records to only display those that qualify. The trick is I want the user to be able to type in info and have it check all the fields of the form and return records for any that are valid.
I set up a query with the fields that I want checked and I watched a few tutorials on setting criteria, but they are all working with multiple search bars. Is there a way to do it with only 1?
Like "*" Or [Forms]![Publications Page]![FilterBox] OR "*"
This is the criteria expression I wrote. It returns records just not the ones I want and doesn't seem to change after I change what is in [FilterBox]. I have 4 fields I'm running this same criteria on. All thoughts and suggestions are greatly appreciated!
Thanks!
The resulting criteria should be something like
[LastName] Like '*searchtext*' Or [FirstName] Like '*searchtext*' Or ...
So, you would have to set up a single criteria like this
Dim crit As String
crit = " Like '*" & Replace(Me!FilterBox, "'", "''") & "*' "
where the replace statement replces single (') by 2. This enables the user to enter an apostrophe in the search box.
Now you must create the whole criteria
crit = "[Field1]" & crit & "Or [Field2]" & crit & "Or [Field3]" & crit & "Or [Field4]" & crit
I am experiencing an issue with Access 2013 while creating some VBA code with a button. I would like my button to open an form using: DoCmd.OpenForm
With this command i would like to implement an WHILE condition which filters the form which is going to be opened.
I have 2 fields on the current form with:
- Start Date
- End Data
The WHILE condition must filter all records Where the column "Date" is between the 2 given dates in the previous form. So actually i would like to do something like this:
WHERE date >= Me.begin_date.value AND date <= Me.eind_date.value
I cant simply figure it out to use it in the WHILE condition of the VBA code. I can however do other things with filters in VBA like:
search_filter = "ItemID LIKE '*" & Me.search_bar.Value & "*' "
DoCmd.OpenForm "#3 search-result", acNormal, , search_filter
But now i want to have the first code sample, translated to the VBA code just like the above piece of code.
How can i achieve this?
Sorry for my bad English btw.
if i recall correctly;
generate a query based on those two values (in the query builer will do) then
forms!formname.recordsource = sql for that query here
My Question was answered on another forum (tweakers.net).
search_filter = "Date BETWEEN #" & Me.begin_date.Value & "# AND #" & Me.end_date.Value & "#"
It did the trick.
I need to grab the Month and Year info from 2 date/time parameters of my report (Start date and End date) into a textbox.
I used the following expression -
=MonthName(Month(Parameters!StartDate.Value)) & Format(Year(Parameters!EndDate.Value)) & " to " & MonthName(Month(Parameters!EndDate.Value)) & Format(Year(Parameters!EndDate.Value))
to get it into something like e.g. March 2012 to August 2012.
It works, however I keep getting the following Warning:
[rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox18.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from type 'Date' to type 'Integer' is not valid.
Any ideas?
Thanks!
Is that the exact expression you are using? It doesn't seem like it is because:
that expression works without warnings (on my system)
it doesn't give the output that you indicate it does
the expression is wrong (it lists the year of the EndDate twice rather than the StartDate's year with the StartDate's month)
So I would guess that one of the functions in the actual expression is MonthName(Parameters!StartDate.Value) rather than MonthName(Month(Parameters!StartDate.Value)) which would give the error indicated.
This also works:
=MonthName(Month(Parameters!StartDate.Value)) & " " & Year(Parameters!StartDate.Value).ToString() & " to " & MonthName(Month(Parameters!EndDate.Value)) & " " & Year(Parameters!EndDate.Value).ToString()
Either that or this isn't the expression in Textbox18