Separate multiple selected address from GetAddress Method - vba

This is a simple question really.
But I'm having a hard time to solve it.
Background:
I'm trying to get email address using .GetAddress Method of Word.Application Object.
Now, I don't have problem if the user selects single To and CC recipients.
Problem occurs when multiple emails get selected by the user.
For example, the user selects two email address and one group list.
rawRecip = Application.GetAddress(, "<PR_DISPLAY_NAME>", , 1, 2, True)
Debug.Print rawRecip
Using above code produces:
Smith, John, Joe, Jane, All-HQ Group
Each address selected is separated by a <comma><space>.
The problem is SurName and GivenName are also separated by the same.
Now I need to successfully get the display name of the 3 address selected by the user.
Split function doesn't get me anywhere since I cannot find or generate a unique delimiter that would separate the 3 display name.
Is there a clean way to get what I want?
Smith, John
Joe, Jane
All-HQ Group

Unbelievable. The answer is already in front of me.
Posting this as answer just in case someone needs it.
You just need to add another character in the GetAddress Method.
Edit:Using another space character gives the best result
rawRecip = Application.GetAddress(, "<PR_DISPLAY_NAME>" & " ", , 1, 2, True)
It will produce:
Smith, John , Joe, Jane , All-HQ Group
Then you can use Split function and some text manipulation to get the desired result.
Dim i As Integer, dName
dName = Split(rawRecip, " , ")
For i = LBound(dName) To UBound(dName)
Debug.Print dName(i)
Next
And the result:
Smith, John
Joe, Jane
All-HQ Group
Note:with extra space on the last entry

Related

Alteryx Designer - How to retrieve only first and last name from field excluding middle initials?

I need help in writing SQL code in Alteryx Designer.
My table employees contains a column Name with values shown below. However, I need the expected output as shown below.
Please help.
Name:
Smith, Mary K
Koch, J B
Batoon Rene, Anne S
Vaughan-tre Doctor, Maria S
Excepted output:
Smith, Mary
Koch, J
Batoon Rene, Anne
Vaughan-tre, Maria
The middle initials and “Doctor” word is removed.
Not sure why you need to use SQL if you have the data in Alteryx?
So, you need to remove the right hand 2 characters and the word 'Doctor' from each record?
You could use the Formula tool, though I suspect there are numerous other ways:
replace (TrimRight([Name],' '+right([Name],1)),'Doctor','')

Using LIKE clause when formats are different

I was given a patient list with names and I am trying to match with a list already in our database and am having troubles given the format of the name field in the patient list. This list is taken from a web form so people can input names however they want so it does not match up well.
WEBFORM_NAME
PATIENT_NAME
JOHN SMITH
SMITH,JOHN L
SHANNON BROWN
BROWN,SHANNON MARIE
Is there a way to use a LIKE clause in an instance like this? All I really need is the LIKE clause to find the first name because I have joined on phone number and email address already. My issue is when households have the same phone number and email address (spouses for example) I just want to return the right person in the household.
Not sure if all you need is to get first name, here is the WIldCard expression to get first name
SELECT LEFT(WEBFORM_NAME,CHARINDEX(' ',WEBFORM_NAME)-1) AS FirstName1,
SUBSTRING(PATIENT_NAME,CHARINDEX(',',PATIENT_NAME)+1,(CHARINDEX(' ',PATIENT_NAME)-CHARINDEX(',',PATIENT_NAME))) AS FirstName2
FROM yourTable
The assumption here seems to be that the webform (where user would manually) type in the name would be of the format <First Name> [<optional middle Name(s)>] <Last Name>, where as the data stored in the table are of the form <Last Name>,<First Name> [<optional middle Name(s)>]. Its not an exact science, but since other criteria (like email, phone etc) have been matched best case
select *
from webform w, patient p
where
-- extract just the last name and match that
regexp_like(p.name,
'^' ||
regexp_extract(w.name,
'([^[:space:],][[:space:],])*([^[:space:],]+)', 1, 2))
and -- extract the first name and match it
regexp_like(p.name,
',[[:space:]]*' ||
regexp_extract(w.name, '(^[^[:space:],]+)'))
Since webform is free form user input, its hard to handle abbreviated middle name(s) and other variations so using the above will do first name and last name based matching which in addition to the matching you are already doing should help.

SQL query to get the first letter of each word and seperate it by a dot and a space

I have never really used SQL much but recent changes due to working from home is forcing me to gain some knowledge in it. I have been doing fine so far but I am now running into a problem that I can't seem to find a solution for.
I have an excel sheet that pulls customer information trough a SQL query which runs by VBA code.
What I first needed to do is to get a full name from a customer and input this into the sheet. This works fine. I am using the following query for this:
Select concat(concat(Customer_First_Names,' '), Customer_Last_Name) FROM CustomerInformationTable where Customer_Number = &&1
This gives me the full name of a customer and spaces in between the first and last name and in between the names (the full first names are already spaced in between in the table).
Now, I got another request to not retrieve the first full first names and last name of a customer, but their initials and the last name.
For example:
Barack Hussein Obama
Would become
B. H. Obama
I need to do 2 things for this:
I need to change my query to retrieve only the initials for each first name. Like I said, all full first names (even if a customer has more then one first name) is located in the column Customer_First_Names.
I need to add a dot and a space after each initial.
How would I go on about this?
I have been thinking about using SUBSTRING but I am struggling on how to do this if there is more then one first name.
So this is not going to work:
Select concat(substr(Customer_First_Names, 1, 1), '. ') from CustomerInformationTable where Customer_Number = &&1
My apologies if this has already been ask on the board so far, I looked but I did not find a suitable solution.
Assuming you don't want to see 2 dots after someone who has just one first name (like J.. Smith), then here's a solution that works in postgres. Not sure what your db is, so you may need to adjust as needed.
The 'with' query is splitting apart the first names, limiting to two.
The 'case' statement then checks if the person has a second first name. If not, then only the first initial is provided and followed by a dot. Otherwise, both first initials are followed by a dot. Final results, all initials and names are separated by a space (like T. R. Smith).
So, a table looking like this:
cid first last
1 JAKE SMITH
2 TERREL HOWARD WILLIAMS
3 PHOEBE M KATES
Will produce the following results with the query below.
cid cust_name
1 J. SMITH
2 T. H. WILLIAMS
3 P. M. KATES
with first_names as
(select distinct customer_number ,
split_part(customer_first_name, ' ', 1) as first1,
split_part(customer_first_name, ' ', 2) as first2
from CustomerInformationTable
)
select distinct customer_number,
case
when fn.first2 = '' then substring(fn.first1, 1, 1) || '.'
else substring(fn.first1, 1, 1) || '. ' || substring(fn.first2, 1, 1) || '.'
end
|| ' ' || a.customer_last_name as cust_name
from CustomerInformationTable a
join first_names fn on fn.customer_number = a.customer_number

Excel 2013 VLOOKUP() based on multiple criteria, retrieving multiple rows

I have an issue that can (I believe) be solved by just excel, and may won't require VBA (I could be wrong). I believe it can be solved by nested functions but the formula I've tried has not worked.
Here's my data:
Name Report # Name
Mark Doe ReportXXX Mark Doe
Connie Doe ReportYYY Connie Doe
Debbie Doe REPORTYYY Debbie Doe
Valerie Doe FSMVALTR1 Valerie Doe
Jeff Doe FSMVALTR1 Jeff Doe
Andy Doe RAZXYBCA1 Andy Doe
Ryan Doe RAZXYBCA1 Ryan Doe
Andy Doe RAZ111111 Jill Doe
Ryan Doe RAZ222112 Amanda Doe
This list goes on for about ~4000 rows in the first NAME and REPORT # columns. In the second NAME column I have ~160 rows.
The second name column identifies all the users who actually use the report, with no duplicates. The two name and report # columns have many duplicates, since users have access to multiple reports, and many of them are the same report used for different purposes. Since the second NAME column has so few rows, the names don't match up all the way through, which can be observed near the bottom of both the NAME columns.
What I need to do is have a VLOOKUP that identifies the name in both of the columns and then returns the report number that each individual has access to across rows (horizontally), not down the columns. It also needs to I.D. numerous reports since individuals have access to anywhere from 1-15 reports, starting at the second and so on after the previous has been extracted.
Ideally it would look something like this:
Name Report # Name ex column ex column ex column
Mark Doe ReportXXX Mark Doe ReportXXX ReportAAA ReportB
I didn't list the other reports "Mark Doe" has access to and these would be somewhere down the long list of ~4000, along with his name repeated multiple times in the first NAME column, but the second "unique" name column would be where it is returning the reports to, across rows.
I made a method that uses additional three columns and it worked for me.
I used the data you provided above.
Add three columns to the left.
in A2 enter =COUNTIFS($D$2:$D2,D2,$E$2:$E2,E2).
in B2 enter =SUMIFS($A$2:$A2,$A$2:$A2,1,$D$2:D2,D2).
in C2 enter =D2&B2.
Now copy those cells to all your 4000 rows.
Now next to the second name column add column headers numbered from 1 to as many reports you think can be the max one user can have (you said 15).
Now enter this vlookup in F2 =IFERROR(VLOOKUP($F2&G$1, your table array starting from column C as absolute/fixed ,3,FALSE),"") in my case it was =IFERROR(VLOOKUP($F2&G$1,$C$2:$E$11,3,FALSE),"").
Copy the formula accross all columns with number headers and down all rows that have names in second name column (160).
your sheet shuld look something like this image
All the best let me know if it worked for you.
Have you explored the option of using a Pivot Table?
The output would look like this:
With the Pivot Table setup like this:
This method would make for a cleaner view, as your current method looks to repeat ~4,000 times (once for each report & name combo). Hopefully this works for what you need.

sql create a field from a field

I need to run a query that would pull information from a field that has 2 types of data .
Field is address and has 123 avenue as data and bb#yahoo.com.
I need to make 2 fields one for email and one STaddress from table customer and field address?
anyone can i assis..
its access and vb query
I thought of this
Select customer.address from customer where address like "#"
but still i need to display the the data of address field to 2 different fields...
Here is the query that fetches the two different fields:
select iif(field like '*#*', field, NULL) as email,
iif(field like '*#*, NULL, field) as address
from t
The usage of like in Access is a bit different from other databases.
I would suggest that you create a view with this logic. If you actually want to modify the table, you will have to add columns and populate them with logic like the above.
Based on this question and your duplicate question, I understand your table has a field which includes both the street address and email address and you want to split those into separate fields.
So your table includes this ...
YourField
------------------------------
1234 ave willie haha#yahoo.com
123 avenue bb#yahoo.com
And you want this ...
YourField street_address email_address
------------------------------ --------------- --------------
1234 ave willie haha#yahoo.com 1234 ave willie haha#yahoo.com
123 avenue bb#yahoo.com 123 avenue bb#yahoo.com
If that is correct, you can use the InstrRev() function to determine the position of the last space in YourField. Everything before the last space is the street address; everything after is the email address.
SELECT
y.YourField,
Left(y.YourField, InstrRev(y.YourField, ' ') -1) AS street_address,
Mid(y.YourField, InstrRev(y.YourField, ' ') +1) AS email_address
FROM YourTable AS y;
You may need to add a WHERE clause to ensure the query only tries to evaluate rows which include your expected YourField value patterns.
Try something like this:
select *,
(case locate('#', address) when 0 then null else address) as email,
(case locate('#', address) when 0 then address else null) as street
from table;
You'd probably need to adjust the name of "locate" function - I'm not sure if it is the same in access database.
If you have a street address and then an email address in the same field, and want to split them, then use this.
We'll call your original field Addy, and the new fields Street & Email.
SELECT Left(Addy, InStrRev(Addy, " ", InStr(Addy, "#")) - 1) AS Street, mid(Addy, InStrRev(Addy, " ", InStr(Addy, "#")) + 1) AS Email.
What this does is look for the #, then go backwards and look for the first space. The first function takes every left of that space and calls it Street, while the second function takes everything to the right.
The function is really 3 functions nested together. To really understand what it's doing, I'll dissect it.
I = InStr(Addy, "#")
J = InStrRev(Addy, " ", I)
Street = Left(Addy,J-1)