SSRS Choose Parameter to Show in Header - reporting-services

I have a report for my customers where they can input a Premise Number, Tax ID, Service Number, or Address to search by. I've set these four options as my parameters.
I'd like to show whichever they have selected in my header. Right now, my header looks like this;
Service for
Premise: __whatever they select__
Tax ID:
Service ID:
Address:
Expression Code looks like this;
="BACKFLOW SERVICE / DEVICES / TESTS" & vbcrlf &
"for Premise#: " & Parameters!premise.Value & vbcrlf &
"for Tax Parcel ID: " & Parameters!TaxParcelID.Value & vbcrlf &
"for Premise-Svc: " & Parameters!SvcNum.Value & vbcrlf &
"for Address: " & Parameters!SvcAddr.Value
But, instead, I would like for my header to only show whatever they've selected. If they're searching by address, I'd like for my header to say;
Service for
Address: ___address here___
How can I do that?

You can do this by checking the parameters for values with an IIF Statement. You can do something like what is below.
="Service for " & vbcrlf &
IIF(ISnothing(Parameters!premise.Value), '', "for Premise#: " & Parameters!premise.Value & vbcrlf) &
IIF(ISnothing(Parameters!TaxParcelID.Value), '', "for Tax Parcel ID: " & Parameters!TaxParcelID.Value & vbcrlf) &
IIF(ISnothing(Parameters!SvcNum.Value), '', "for Premise-Svc: " & Parameters!SvcNum.Value & vbcrlf) &
IIF(ISnothing(Parameters!SvcAddr.Value), '',"for Address: " & Parameters!SvcAddr.Value)

Related

MS Access Tag property - how its identifying update and insert operation?

I trying to create Add,update,Delete operation on MS Access form.I found this code on internet where Insert and update is happening on the same button. I am not getting what is exactly happening in below line and how it's identifying it is for update or insert.
Not getting following line : = Me.txtid.Tag & "" = ""
Please find below code which works perfect as per requirement.
'When we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtid.Tag & "" = "" Then
' this is for insert new
' add data in table
CurrentDb.Execute "insert into student(stdid,stdname,gender,phone,address)" & _
" values(" & Me.txtid & ",' " & Me.txtname & " ',' " & Me.cmbgender & " ','" & _
Me.txtphone & "', '" & Me.txtaddress & "')"
'refresh data in list on form
subform_student.Form.Requery
Else
CurrentDb.Execute "UPDATE student " & _
" set stdid = " & Me.txtid & _
", stdname = '" & Me.txtname & "' " & _
", gender = '" & Me.cmbgender & " ' " & _
", phone = ' " & Me.txtphone & " ' " & _
", address = ' " & Me.txtphone & " ' " & _
" WHERE stdid = " & Me.txtid.Tag
End If
The .Tag property is a general-purpose string property of every form and control object in VBA/VB6. It is provided as a place for developers to "put stuff" to support the operation of their applications.
The original code from which you copied your sample must have written a value to Me.txtid.Tag when the record was loaded (e.g., perhaps in the form's Current event) to indicate whether the record is an existing record or a new record (empty="new", non-empty="existing"). The line
If Me.txtid.Tag & "" = "" Then
simply checks to see if the .Tag property is empty, and then performs the INSERT or UPDATE accordingly.
BTW, re:
below code which works perfect as per requirement
No, it doesn't. Try adding a record where [stdname] is Tam O'Shanter and see for yourself. You should ditch the dynamic SQL and use one of
a bound form (as Gustav suggests),
a parameterized query, or
a recordset update.
Forget/remove all this code and bind the form to table Student to make this all happen automatically.
If a bound form is not familiar to you, browse for a tutorial for "Beginning with Microsoft Access" or the like.

Why is my vbCrLf not working?

I have to declare a variable in which I need to keep multiple sentences (vbscript is the language I am using). So, I put vbCrLf at the end of sentences in order to get a break. But it is not giving me the break instead it is giving me a whole paragraph.
strHtmlBody = "<div><font face='Arial' size='-1'>Greetings "& RS("firstname") &":"& vbCrLf & _
"Here is the email that contains your account information to access your account at www.example.com." & VbCrLf & VbCrLf & _
"Your Email Address: " & RS("Email") & VbCrLf & _
"Your Password : " & RS("Password") & VbCrLf & vbCrLf & _
"Remember, if you have any questions or concerns, please let us know, simply reply to this email." & VbCrLf & _
"ABC Company" & vbCrLf & _
"http://www.example.com" & vbCrLf & vbCrLf
strHtmlBody = strHtmlBody & "</div>"
HTML ignores most whitespace which vbCrLf represents. Use <br> tags in its place.

Need to format code for querying with exact value from combo box

I have the following ms access query. I want it to query with the gender (female or male) selected from the combo box. At the moment, when I select "female", the query results also includes all male persons.
How should I format this code:
WHERE (((Q_Gender_Statistics.Year) Like [cboYear] & "*") AND ((Q_Gender_Statistics.Gender) Like "*" & [cboGender] & "*"))
Don't use Like if not needed:
" WHERE Q_Gender_Statistics.Year = " & [cboYear] & " AND Q_Gender_Statistics.Gender = '" & [cboGender] & "'"
If cboGender looks up "Male/Female" form an index value, try this:
" WHERE Q_Gender_Statistics.Year = " & [cboYear] & " AND Q_Gender_Statistics.Gender = " & [cboGender] & ""

DoCmd multiple where clauses

I have form where user can search the database by worker ID , name/surname, job.
I want to make possible all possible variations e.g. ID+name/surname+job or ID+job, or name/surname etc.
I have done all except combinations with ID's. Searching only by ID works, but combinations don't as I do not know what is the correct syntax. I have tried many, many ways to do this, but with no result.
Here is searching only by ID:
DoCmd.OpenForm "DarbiniekiSearchResults", acFormDS
Forms!DarbiniekiSearchResults.RecordSource = "" _
& "SELECT * " _
& "FROM Darbinieks " _
& "WHERE ID_darbinieks=" & Forms!SearchDarbinieki!darbIDsearch
And here is what I am trying to do: ID+job:
DoCmd.OpenForm "DarbiniekiSearchResults", acFormDS
Forms!DarbiniekiSearchResults.RecordSource = "" _
& "SELECT * " _
& "FROM Darbinieks " _
& "WHERE ID_darbinieks= & Forms!SearchDarbinieki!darbIDsearch OR amats_darb= '" & Forms!SearchDarbinieki!darbAmatsSearch & "'"
And the error is: http://i.stack.imgur.com/NA2bi.png

Too few parameters, expected 1? error access

I am getting the above error whilst running this commmand:
CurrentDb.Execute "UPDATE VolunteerDetails " & _
" SET FirstName=" & Me.frst_Name_txt & _
", LastName='" & Me.lst_Name_txt & "'" & _
", PostalCode='" & Me.pst_Code_txt & "'" & _
" WHERE VolsID=" & Me.vol_ID_txt
Can anyone explain why?
Thanks!
I think your problem is in the FirstName value. It seems to be a string and so you need to put your value inside single quotes
CurrentDb.Execute "UPDATE VolunteerDetails " & _
" SET FirstName='" & Me.frst_Name_txt & "'" & _
", LastName='" & Me.lst_Name_txt & "'" & _
", PostalCode='" & Me.pst_Code_txt & "'" & _
" WHERE VolsID=" & Me.vol_ID_txt
Said that, please read about Sql Injection and Parameterized queries. Your code, as is, it is very weak and could fail simply if someone types a LastName like O'Malley (the single quote breaks your string concatenation)
As pointed by a comment above, I suppose that these variables are not TextBoxes but just string variables. If these are TextBoxes then, the value to set the field to comes from the Text property of the TextBox. Something like
" SET FirstName='" & Me.frst_Name_txt.Text & "'"