Joeclueless
Technical User
I have an address field named [STREET].
examples of values:
STREET
4103 SANTA ROSALIA DR #D
12763 DE HAVEN AV
2348 W 255TH ST
547 1/4 S BREED ST
1163 S HOOVER ST #1
1909 1/2 TALMADGE ST
4806 1/2 FIRESTONE BL
5544 YOLANDA AV #307
4859 1/4 N LONG BEACH AV WEST 27
I want to parse these values into a maximum of 7 fields.
[HSE_NBR] = house number (ex. 4859)
[HSE_FRAC_N] = house number fractional suffix (ex. 1/4)
[HSE_DIR_CD] = address direction (ex. N)
[STR_NM] = street name (ex. LONG BEACH)
[STR_SFX_CD] = street suffix/type (ex. AV)
[STR_SFX_DI] = street suffix direction (ex. WEST)
[UNIT_RANGE] = unit number (ex. 27)
Not all records have all 7 pieces of information. In fact, I don’t think any records have all 7. The example: "4859 1/4 N LONG BEACH AV WEST 27" is a hypothetical potential value.
I'm having some difficulty though.. I need to look at each StrIn and have the module "Decide" which output field to drop it into....
This is what I have so far... This has been modified from a post from a few years back by a GREAT INDIVIDUAL Tranman in:
thread701-244291
Anything helps!
Thanks again!
Joe
examples of values:
STREET
4103 SANTA ROSALIA DR #D
12763 DE HAVEN AV
2348 W 255TH ST
547 1/4 S BREED ST
1163 S HOOVER ST #1
1909 1/2 TALMADGE ST
4806 1/2 FIRESTONE BL
5544 YOLANDA AV #307
4859 1/4 N LONG BEACH AV WEST 27
I want to parse these values into a maximum of 7 fields.
[HSE_NBR] = house number (ex. 4859)
[HSE_FRAC_N] = house number fractional suffix (ex. 1/4)
[HSE_DIR_CD] = address direction (ex. N)
[STR_NM] = street name (ex. LONG BEACH)
[STR_SFX_CD] = street suffix/type (ex. AV)
[STR_SFX_DI] = street suffix direction (ex. WEST)
[UNIT_RANGE] = unit number (ex. 27)
Not all records have all 7 pieces of information. In fact, I don’t think any records have all 7. The example: "4859 1/4 N LONG BEACH AV WEST 27" is a hypothetical potential value.
I'm having some difficulty though.. I need to look at each StrIn and have the module "Decide" which output field to drop it into....
This is what I have so far... This has been modified from a post from a few years back by a GREAT INDIVIDUAL Tranman in:
thread701-244291
Code:
Option Compare Database
Public Function ParseFld()
Dim intPtr As Integer 'Pointer for location of multiple spaces in strIn variable
Dim intlen As Integer 'Variable to hold length of strIn variable
Dim strIn As String 'Common named variable for use as input field
Dim conDB As New adodb.Connection 'Connection to the current database
Dim rsIn As New adodb.Recordset 'Recordset to fetch unparsed input data from Input Recordset
Dim rsOut As New adodb.Recordset 'Recordset to insert parsed data into Output Recordset
Dim strSQLIn As String 'SQL string to query up input data
Dim strSQLOut As String 'SQL string to create recordset based upon structure of SampOutput
'Set up SQL statements
strSQLIn = "Select * from lausd_sis_fall04;"
strSQLOut = "Select * from hseno_01_test;"
'Now open the connection to the current database
conDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data_Models\hsenum\Data_Parsing.mdb;Persist Security Info=False"
'Then, open up the two recordsets.
'rsIn will contain all of the data from the lausd_sis_fall04 table
'rsOut will contain all of the data from the hseno_01_test table (which is no data because we have
'not added any yet, but rsOut will still contain a field for each column in hseno_01_test
rsIn.Open strSQLIn, conDB, adOpenDynamic, adLockOptimistic
rsOut.Open strSQLOut, conDB, adOpenDynamic, adLockOptimistic
'At this point, the rsIn recordset contains a snapshot of the entire lausd_sis_fall04 table, and we can
'move through the recordset, processing fields (columns), updating them if we wish, deleting
'rows, or whatever. We are just going to move through the recordset from beginning to end,
'first, moving the LAUSD_ID from the rsIn recordset to the rsOut recordset, and thus to the
'hseno_01_test table, and then parsing out and moving the contents of STREET, one field
'at a time into rsOut, and thus to hseno_01_test.
'JoeC, you just need to accept this connection/recordset functionality and not worry too
'much about how it works.
'First, be sure we are pointed to the first row of rsIn
rsIn.MoveFirst
'Next, we delete all rows from hseno_01_test to make sure no artifacts were left there by a
'previous run
conDB.Execute "Delete from hseno_01_test;"
'Now, we process each row of the recordset, one at a time until we reach rsIn.EOF
Do While Not rsIn.EOF
'Add a new (blank) row to hseno_01_test
rsOut.AddNew
'Move LAUSD_ID field from rsIn to rsOut (and thus to hseno_01_test)
rsOut.Fields("LAUSD_ID") = rsIn.Fields("LAUSD_ID")
'Move LAUSD_ID field from rsIn to rsOut (and thus to hseno_01_test)
rsOut.Fields("ZIP_CD") = rsIn.Fields("ZIP")
'Move unparsed field into strIn here. (We use strIn as a work area.)
'Note: reference could be rsIn.Fields(1)
strIn = rsIn.Fields("STREET")
'Now, we start parsing the field
strIn = Trim(strIn) 'get rid of any leading/trailing spaces
'Now, we parse out the remainder of strIn (the variable-length part)
'Here, we find the first occurance of a space in strIn
intPtr = InStr(strIn, " ")
'And then move all characters to the left of a space into the HSE_NBR field
rsOut.Fields("HSE_NBR") = Left(strIn, intPtr - 1)
'Then we strip the HSE_NBR data off of the front of strIn
intlen = Len(strIn)
strIn = Right(strIn, (intlen - intPtr) + 1)
'Then we strip the leading space(s) off of strIn
strIn = Trim(strIn)
'Then we find the next occurance of a space
'Are you beginning to see a pattern here?
intPtr = InStr(strIn, " ")
'Then we move all characters to the left of the multiple spaces into the HSE_FRAC_N field
rsOut.Fields("HSE_FRAC_N") = Left(strIn, intPtr - 1)
'Then we strip the HSE_FRAC_N data off of the front of strIn
intlen = Len(strIn)
strIn = Right(strIn, (intlen - intPtr) + 1)
'Then we strip the leading space(s) off of strIn
strIn = Trim(strIn)
'Then we find the next occurance of a space
intPtr = InStr(strIn, " ")
'Then we move all characters to the left of the multiple spaces into the HSE_DIR_CD field
rsOut.Fields("HSE_DIR_CD") = Left(strIn, intPtr - 1)
'Then we strip the HSE_DIR_CD data off of the front of strIn
intlen = Len(strIn)
strIn = Right(strIn, (intlen - intPtr) + 1)
'Then we strip the leading space(s) off of strIn
strIn = Trim(strIn)
'Then we find the next occurance of a space
intPtr = InStr(strIn, " ")
'Then we move all characters to the left of the multiple spaces into the STR_NM field
rsOut.Fields("STR_NM") = Left(strIn, intPtr - 1)
'Then we strip the STR_NM data off of the front of strIn
intlen = Len(strIn)
strIn = Right(strIn, (intlen - intPtr) + 1)
'Then we strip the leading space(s) off of strIn
strIn = Trim(strIn)
'Then we find the next occurance of a space
intPtr = InStr(strIn, " ")
'Then we move all characters to the left of the multiple spaces into the STR_SFX_CD field
rsOut.Fields("STR_SFX_CD") = Left(strIn, intPtr - 1)
'Then we strip the STR_SFX_CD data off of the front of strIn
intlen = Len(strIn)
strIn = Right(strIn, (intlen - intPtr) + 1)
'Then we strip the leading space(s) off of strIn
strIn = Trim(strIn)
'Then we find the next occurance of a space
intPtr = InStr(strIn, " ")
'Then we move all characters to the left of the multiple spaces into the STR_SFX_DI field
rsOut.Fields("STR_SFX_DI") = Left(strIn, intPtr - 1)
'Then we strip the STR_SFX_DI data off of the front of strIn
intlen = Len(strIn)
strIn = Right(strIn, (intlen - intPtr) + 1)
'Then we strip the leading space(s) off of strIn
strIn = Trim(strIn)
'At this point, what is left in strIn is the data for the UNIT_RANGE field so we put it there
rsOut.Fields("UNIT_RANGE") = strIn
'Then we update the recordset (which inserts the recordset row into the table)
rsOut.Update
'Then we move forward to the next input row (this is like doing a read)
rsIn.MoveNext
'Then we loop back to the top and process the next row
Loop
'When we get here, we have processed all input rows. Next we:
'Close the recordset objects
rsIn.Close
rsOut.Close
'Close the ADODB connection object
conDB.Close
'Release the objects' memory resources back to the system
Set rsIn = Nothing
Set rsOut = Nothing
Set conDB = Nothing
End Function
Anything helps!
Thanks again!
Joe