Here's a fun one, I've read a number of forums that describe this very situation and the solutions are case by case. This one in particular, I managed to get to work but for some reason it stopped working after restarting Access.
Background: Unfortunately, the data that I need to use here is done by a different office, in a galaxy far far away and, despite our complaints and profesional emails the Member and Supervisor values are filled using different formats. I've been trying to write a statement that will identify the supervisees of each member. End Background:
The Member format is: Last, First [sometimes a middle initial, sometimes full middle name]
The Supervisor format is: Last First (some supervisors are left null and in some cases a number... it's pretty messy).
Rather than fixing each value by hand, I've thought of two methods. I could use an SQL statement to make up for the difference, or I could write a VBA script to fix all of the cells when I update the database from the spreadsheet that we recieve. (Or we could continue to do it line by line but the process is time consuming).
So far, I've managed this SQL statement:
Using Table MEMBER in a recursive join to MEMBER_1 and columns FULL_NAME (for each member) and SUPV_NAME (for the supervisor).
SELECT MEMBER.SUPV_NAME, MEMBER.FULL_NAME
FROM MEMBER INNER JOIN MEMBER AS MEMBER_1 ON LEFT(MEMBER.SUPV_NAME,(InStr(Nz(MEMBER.SUPV_NAME," 0"), ' ')-1)) = LEFT(MEMBER_1.FULL_NAME,(InStr(MEMBER_1.FULL_NAME, ' ')-2));
This finds the text until a space for SUPV_NAME (which has no comma) then does the same for FULL_NAME (which has a comma, hence -2) then compares them. Also, I use Nz because Supervisor is sometimes null (even though it shouldn't be). The statement LEFT(MEMBER.SUPV_NAME,(InStr(Nz(MEMBER.SUPV_NAME," 0"),' ')-1)) works as a SELECT statement, the probelm comes up when I try to compare it to MEMBER_1.FULL_NAME in the JOIN. I get this error: "Invalid Procedure Call".
So close, and yet so far. Does anyone have any ideas on how I could get this to behave properly? As it stands, if this did work, it would only compare last names, I figured I'd work on getting it compare first names as well if I can get this far. Otherwise, I'm not really sure what's causing the error.