Textbox without spaces in between - sql

I have this SQL table where there are 6 address fields ...
Address 1
Address 2
Address 3
Address 4
Address 5
Address 6
I have to club all the address fields into one text box in ssrs. So that the whole address is displayed in the same text box field.
Plus the condition in the requirement is in the pic below.
Display the address lines one below the other in the repor. If any field is empty skip and display the next field. Don't leave the space
I tried using (iif statements) ...but this doesn't seem to help ... Somewhere or the other there were gaps in the text box ..
Fields!address1.values & vbcrlf + Iif(isnothing(fields!address2.values = "",fields!address3,fields!address2.values) Iif(isnothing(fields!address3.values = "",fields!address3,fields!address3.values) Iif(isnothing(fields!address4values = "",fields!address3,fields!address4.values) ....

This would actually likely be easier in the SQL layer. Then you can just use CONCAT_WS:
CONCAT_WS(' ',Address1, Address2, Address3) AS FullAddress

If you need to use an expression would something in this form work ?
iif(isnothing(Fields!address1.values,"", Fields!address1.values & vbcrlf) &
iif(isnothing(Fields!address2.values,"", Fields!address2.values & vbcrlf) ... etc.

Related

Add Bcc addresses from a column of a datagridview

I'm creating a program that reads a column of a datagridview that contains email addresses and inserts them as Bcc.
I would like to write multiple email addresses in the Bcc.
I can enter one email address.
Mail.Bcc.Add(New MailAddress(Form10.DataGridView1.Rows(3). Cells(4). Value))
I would like to take all the column 4 of my datagridview.
Assuming you mean that you have multiple email addresses in the cell, presumably separated by some form of delimiter, then you can achieve what you want with code similar to this:
Dim MyEmailAddresses() As String, EmailAddress As String
MyEmailAddresses = Split(Form10.DataGridView1.Rows(3).Cells(4).Value, ",")
For Each EmailAddress In MyEmailAddresses
Mail.Bcc.Add(New MailAddress(EmailAddress)
Next EmailAddress
In this case, I have assumed that your email addresses are comma separated. If you use a different delimiter, simply replace "," with whatever delimiter you are using.

How to add a wildcard to combobox-selected value to broaden values returned in multiple item form

I have a multiple item form which displays client records, e.g., first and last name, date of birth, address, etc… The same client can be listed multiple times in multiple ways and may have the same or similar name as other clients (because bad historic data process). Jim Smith, James Smith, and Jim Smith Jr. could be the same or more than three different people (with date of birth and other information helping to resolve such issues).
I have set up two combo boxes to filter the form sequentially, but I need some help getting them to function as desired. The first combo pulls the list of distinct last names from the underlying table via a simple select query. Once a name is selected the second combo box offers the set of distinct first names with the selected last name.
Is there a way to use the selected last name plus wildcards in the vba so that selecting “Smith” would also return “Smith Jr.”, “Smith-Jones”, and “Smithers”? Right now I have the following which requeries the second combobox and sets the initial filter on the form, at the moment only to “Smith” in my example:
Private Sub cboFindLast_AfterUpdate()
Me.cboFindFirst.Requery
Me.cboFindFirst = Null
Me.Filter = "LName = '" & Me.cboFindLast & "'"
Me.FilterOn = True
End Sub
This works as desired except for not returning the “Smith+” entries. At this point the user can select from cboFindFirst to reduce the list even more. Again, it would be nice if selecting “Ann” would return Ann, Anna, Annie, and even Ruth-Ann if any of those occur. The code currently on the second box is:
Private Sub cboFindFirst_AfterUpdate()
Me.Filter = "FName = '" & Me.cboFindFirst & "' And LName = '" & Me.cboFindLast & "'"
Me.FilterOn = True
End Sub
Again, this works well and reduces the list to e.g., all of the “Ann Smith” records, but maybe there’s a more recent “Annie Smith-Jones” after she was married and I’d like that record to show as well.
Of course, use LIKE with wildcard:
Me.Filter = "LName LIKE '" & Me.cboFindLast & "*'"
Me.Filter = "FName LIKE '" & Me.cboFindFirst & "*' And LName LIKE '" & Me.cboFindLast & "*'"

SQL SSRS add if condition into ssrs expression

I am creating a simple report in SSRS
One of the fields is an address, which has this expression value
=First(Fields!BILL_CITY.Value) & ", " & Fields!BILL_PROV.Value & " " & Fields!BILL_ZIP.Value
What I want to do, is within that expression within SSRS, I want to add a condition.
If the Fields!BILL_ZIP.Value is only 5 digits, do nothing.
If the value is more than 5 digits, add a dash after the fifth digit.
So if customer sends the shorthand version of the zipcode it will appear as
45040 but if he sends the long version, it will be 45040-8999
Does anybody know how to do this? Creating the condition probably wouldn't be too hard, but how do I put it within the SSRS expression format?
Try:
= IIF(LENGTH(Fields!BILL_ZIP.Value) = 5, Fields!BILL_ZIP.Value & "-", Fields!BILL_ZIP.Value)

Visual Basic - Multicolumn listbox and adding items

So here's the thing; I'm making this home-made sign-up thing for a school project.
I've got first name, last name, date of birth, SS number among other things.
I can send data to another form's listbox
Dim SSID = (tx_SSP.Text)
Datbase_of_User_Information.ListBox1.Items.Add(SSID)
However this will only add ONE item to the listbox. I know there's a way to add in a multi-column data thing into the list
ex:
SSID | Fname | Lname | DoB
Something like the above.
But I've tried doing Listbox1.AddItem("row1 col1", SSID)
and it didn't work.
I had this same problem and I kind of cheated by just putting all the values together into one string and using tabs.
Listbox1.Items.Add(SSID & " " & Fname & " " & Lname & " " & DoB)
I've heard a better solution would be to use a ListView if you want a true multi-column solution.

MS Access multi field search with empty fields

I have a problem very similar to this one, but I just can't seem to solve it!
In MS Access (2003), I want to search a table based on entries in a number of fields, some of which may be empty.
I have:
text fields
date fields
integer fields, and
a memo field (but we can probably not bother searching this one if it is difficult).
They map onto a table exactly.
I am trying to create a query that will return matching rows when data is entered into one or more of these fields, but some fields can be left blank. How the heck do I do this?
A query like the one on the linked question works for text fields, but what do I do about the number fields, date fields (and possibly even the memo field)?
To give a clear example, the following code block works for TextField1, but not NumberField1:
PARAMETERS [Forms]![SearchForm]![FilterTextField1] Text ( 255 ), [Forms]![SearchForm]![FilterNumberField1] Text ( 255 );
SELECT Table1.[TextField1], Table1.[NumberField1], Table1.[TextField2], Table1.[TextField3], Table1.[DateField1], Table1.[DateField2], Table1.[DateField3]
FROM Table1
WHERE (Len([Forms]![SearchForm]![FilterTextField1] & '')=0 OR Table1.[TextField1] Like '*' & [Forms]![SearchForm]![FilterTextField1] & '*') AND (Len([Forms]![SearchForm]![FilterNumberField1] & '')=0 OR Table1.[NumberField1] Like '*' & [Forms]![SearchForm]![FilterNumberField1] & '*');
I do hope you can help. I'm sure I'm missing something really obvious, but for some reason my brain feels like it is leaking out of my ears at the moment.
Thank you!
If you need it, this is the basic design of the relevant entities:
Table1
SomePrimaryKeyWeDontCareAboutRightNow
TextField1
TextField2
TextField3
NumberField1
DateField1
DateField2
DateField3
MemoField1
SearchForm
FilterTextField1
FilterTextField2
FilterTextField3
FilterNumberField1
FilterDateField1
FilterDateField2
FilterDateField3
FilterMemoField1
You can check fo null values or cast to string
You could certainly spend a great deal of time crafting a huge and very hard to debug SQL query for this, or just jump into VBA and write some code to construct just the SQL you need.
VBA is there just for these kinds of scenario, where something is either impossible or becoming too complex to do otherwise.
With VBA, you can use an initial SELECT query that collect all the data, and then construct a WHERE clause based on the content of your search form to filter it.
For instance, I have a form like this, that allows the user to enter any criteria to filter a list of prices:
Some code to implement this could look like:
' Call this whenever the use click the Apply button '
Private Sub btApply_Click()
' Construct the filter '
Dim filter As String
If Not IsBlank(cbSupplierID) Then
If Not IsBlank(filter) Then filter = filter & " AND "
filter = filter & "(SupplierID=" & cbSupplierID & ")"
End If
If Not IsBlank(txtPartNumber) Then
If Not IsBlank(filter) Then filter = filter & " AND "
filter = filter & "(PartNumber LIKE '*" & txtPartNumber & "*')"
End If
If Not ckShowLocked Then
If Not IsBlank(filter) Then filter = filter & " AND "
filter = filter & "(NOT PriceLocked)"
End If
' ... code snipped, you get the jest ... '
' Now re-construct the SQL query '
Dim sql As String
sql = "SELECT * FROM Price"
If Not IsBlank(filter) Then
sql = sql & " WHERE " & filter
End If
SubForm.Form.RecordSource = sql
End Sub
It may seem like a lot of code, but each block only does one thing, and it's a lot easier to debug and maintain than cramming everything into a query.