How to use Parameter field in a record selection "like" statement? - crystal-reports

I have designed a report to pull data fields based on a record selection formula that uses a "like" operator that looks for a substring match in a particular field's data, as so:
{rct.serno} like "*9842*"
(due to the free-format way data is stored in the given field, I have to do a substring match to find the relevant rows in the DB.)
This works fine. Instead of manually editing the record selection formula every time, though, I thought to use a Parameter field ("{?TagNum}") to prompt the user for the desired string, and then use that in the record selection formula like:
{rct.serno} like "*{?TagNum}*"
Crystal does not throw an error when I save this record selection formula, but it does not return any records after the report is refreshed, and a parameter value is entered. How can I properly use the parameter value in a record selection substring match?

You're really close to the solution. You can modify the formula in the Select Expert. Just click the Select Expert icon (or from the Report menu). Then click the Formula Editor button. Concatenate or add an asterisk onto the beginning and end of the parameter using the + operator, like this:
{Customers.LastName} like "*" + {?pLastName} + "*"
Let me know if that helps.
~ Nathan

Related

Access 2010 - enter references to form elements as the value of a text field

Is there a way to take a value from a field on a form and use it as a reference to a different field in the same form, and not just literally? I want to be able to manually enter something like [txtFlavor] in one field and have it show the actual flavor, the value of the field named "txtFlavor" in another field, and not just the string "[txtFlavor]". I'm basically trying to store some vba references (terminology?) in a table so I can bring up a string of text with references to values on the form.
I have been asked to create a system that will store letter templates in Access 2010 and allow users to choose a record with personal information and insert that info into a template letter, preferably displaying it on a form immediately in plain text. I already proposed using reports to do this but that was unacceptable to the end users. They really just want a form that combines
a) contact records, one at a time
with
b) letter templates, one at a time
I've been trying to store the template info with it's form references in a table, but I have yet to be able to make references pull data from another text field on the form.
Is it possible and/or sensible to try to store something like the following in a table, or to enter it into a field on a form?
[txtFlavor] & " is dull but popular."
and then have it show up elsewhere in the form as
Vanilla is dull but popular.
I sure feel dumb and am sure I've missed something obvious. Everything I do is just repeated literally and not interpreted as a reference.
You could get your users to create their templates using 'tags' as placeholders for the database information, in a similar way to how you would design a merge document in Word. So in your example above, the template document would look like:
{Flavor} is dull but popular.
When it comes time to create the merged result you would need to use the Replace function to change these tags to actual data values. So if you had a read-only text box on your form, the control source could be:
=Replace([txtTemplate], "{Flavor}", [Flavor])
I assume you would have lots of potential tags, so using this approach you would need to nest the Replace functions. I have split my nesting across multiple lines to make it a bit more readable:
=Replace(
Replace(
Replace([txtTemplate], "{EmpName}", [EmpName]),
"{EmpAddress}", [EmpAddress]),
"{EmpPhone}", [EmpPhone])
If you had many more database fields/tags this would start to become very unwieldy so I would recommend using some VBA to make life easier, maybe something along the lines of:
Dim rsSource As Recordset
Dim strMerge As String
Dim intField As Integer
'Assuming your form has a field called EmpNo (numeric data) that you can use to pull data...
Set rsSource = CurrentDb.OpenRecordset ("Select EmpName, EmpAddress, EmpPhone From Employees Where EmpNo = " & Me.EmpNo)
strMerge = txtTemplate
For intField = 0 to rsSource.Fields.Count - 1
strMerge = Replace(strMerge, "{" & rsSource(intField).Name & "}", rsSource(intField))
Next intField
txtMerge = strMerge
rsSource.Close
Set rsSource = Nothing
You could put this code in the AfterUpdate event of your txtTemplate text box and it would update the contents of the txtMerge text box. You either need your tag names to match your database columns, or else you could alias the columns in the Select statement so they match the tag names.

Tableau Action URL: field name needed twice to construct a valid link

I've used worksheet URL actions in tableau before and they are Great! But I have a case where to construct a valid link- I need the field twice.
something like....
"http://wwwin-esstools-prd.cisco.com/pmt/emailfilters/EmailFilter.json/?&id=FIELD&queryObj={"conjunction":"and","expressions":[{"op":"equals","attr":"id","value":FIELD}],"preFilterQuery":"","name":"Advanced Filter"}"
where FIELD is the field name I would like to use to properly construct the url. I have tried using both the select and menu options-
both seem to be ignored by tableau.
FIELD needs to be surrounded by angle brackets. You can use the Insert menu on the URL action dialog panel to insert field names into your URL if you prefer, and thus avoid spelling errors. Or simply type the field name and brackets where you want them.

Return different datatypes crystal formula

I have a requirement where depending on the parameter selected the table field should be displayed as text or date. For eg, if the user selects a true, the OriginDate field which is a datetime type should be displayed as a date in the report else should be displayed as a text. I tried creating a formula an doing something like below, and then placing the formula in the details section of the report but it doesnt work due to different datatypes returned.
if {?Mailmerge}=true then
ToText({Travel.OriginDatetime}, "M/d/yy")
else
{Travel.OriginDatetime}
Is there a way I can accompalish the above requirement so that I do not end up creating 2 reports one with field displayed as text and other as date?
Try creating a formula that returns your field as a string totext({Travel.OriginDateTime},"M/d/yy") and overlay it with the original field {Travel.OriginDateTime} and conditionally suppress them based on the value of {?MailMerge} such that only one shows in any one instance of the report.
If I'm following you, you want to only show M/d/yy when ?MailMerge is true, otherwise yuo want to show the full date?
You can't show different datatypes in the same formula, so just convert them both parts of the conditional statement into strings:
if {?Mailmerge}=true then
ToText({Travel.OriginDatetime}, "M/d/yy") // 8/30/12
else
ToText({Travel.OriginDatetime}, "M/d/yy hh:mm:ss") // 8/30/12 02:06:00
I don't know what exactly your dates look like in the database, but you can use the above as a guideline into formatting your date based on the ?MailMerge parameter.

Programmatically show link to another report in Report Builder 3.0?

I have a grouping in my report that I want to use to link to another report. My dilemma is that I only want the link to be clickable when the value in the cell fulfills a certain criteria (number > x for example). If the condition isn't true, then I don't want the cell to be clickable. Is there a way to do this?
Edit: I've tried to set an IIF statement as part of the url, but what do I link to in the "false-part" of the statement? Using "" actually just refreshes the report, which isn't really what I want either. It also complains when I tried about:blank saying the url must start with http:// etc.
Use Nothing keyword in iif expression as false part. If Nothing is specified for Action than no link will be created.
=iif(YOUR_CONDITION, "Other Report", Nothing)
An action isn't dynamic so there's no way to turn it on and off based on a condition. But the expression you use to open another report can use an expression - whether you are using jump to report or the jump to URL action. One thing you might consider is for the condition when you don't want to jump to the other report is to jump to the same report. That is, let's say you are on Report A and you want to jump to Report B only when number > x. Then you use the expression:
=iif(number > x, "Report B", "Report A")
Report A will be cached so the net effect is that you didn't click even though the user can see the cursor change to a hand and can in fact execute a click.

Access 2013 - Embedded query filtered by combo box on form

I'm new to Access and this is the problem I'm suffering: I have four tables - Task, Person, Role, and TaskPerson (mapping table). I have a form that at the top has a unbound combo box displaying a list of people from Person. In the body of the form I have a query pulling from the Task and TaskPerson tables that is embedded as a datasheet. The fields from TaskPerson perform a lookup on Person and Role to display the actual values. Each task can have multiple people assigned to it and each person can have multiple roles. I am looking to pick a name from the combo box with the datasheet updating to only show the tasks associated with that person (i.e. matching the name from the combo box to the name in the person field (which is a lookup) on the form and only showing those tasks).
I have tried adjusting the Record Source for the query so the person field criteria would pull from the combo box using
'Forms![Task Form]![Combo11]'
but that hasn't worked. I have also tried a version of this answer:
Private Sub Form_SelectionChange()
' If the combo box is cleared, clear the form filter.
If Nz(Form) = "" Then
Me.Form.Filter = ""
Me.FilterOn = False
' If a combo box item is selected, filter for an exact match.
' Use the ListIndex property to check if the value is an item in the list.
ElseIf Me.Combo11.ListIndex <> -1 Then
Me.Form.Filter = "[Combo11] = '" & _
Replace(Me.Combo11.Text, "'", "''") & "'"
Me.FilterOn = True
End If
End Sub
While the code is not balking, it also isn't grabbing the selected name from the combo box, so it doesn't update. A likely factor is when I type Me.Combo11.Text, it doesn't actually display Combo11 as an option. I tried typing it in, in hopes of working, but I know that is a bit foolish.
Any detailed answers would be appreciated. I'm still learning my way around and I get lost a bit easily.
Steve.
The first method is the easier one.
In the query you have
WHERE TaskPerson = Forms![Task Form]![Combo11]
Note that there are no ' around the combo reference. With 'Forms![Task Form]![Combo11]' the whole thing is interpreted as string, so it doesn't work.
Then in Combo11_AfterUpdate you simply have
Me.Requery
Disadvantage of this method: you always have to select a person, or the form will be empty.
The second method:
Your query lists all record, the combobox applies a filter. Or removes it, if the user clears the combobox.
I suggest going back to the answer you used, and only replace
Combo_Reported_LOB_Selection by Combo11
and
[ReportedLOB] by [TaskPerson]
And the code doesn't go into Form_SelectionChange(), but into Combo11_AfterUpdate()