G'day everybody,
One of my clients' suppliers sent them a spreadsheet containing price increase data. For Ghu only knows what reason, they have a column with my client's part number and the supplier's description in the same cell.
No problem thinks I, I'll just suck it into Access as a table, Split that field in each record and put the bits where they belong. As below:
[CODE=vb]Private Sub btnFix_Click()
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strInput As String
Dim varInput As Variant
Set db = CurrentDb()
strSQL = "SELECT GoldacrePartNum ber, GasonDescriptio n from GasonNew"
Set rs = db.OpenRecordse t(strSQL, dbOpenDynaset)
Do Until rs.EOF
strInput = rs!GoldacrePart number & " "
varInput = Split(strInput, " ", 2)
rs.Edit
rs!GoldacrePart number = varInput(0)
rs!GasonDescrip tion = RTrim(varInput( 1))
rs.Update
rs.MoveNext
Loop
CleanUpAndLeave :
rs.Close
Set rs = Nothing
Set db = Nothing
DoCmd.Hourglass False
DoCmd.SetWarnin gs True
Exit Sub
End Sub[/CODE]
Well that worked fine except for the record which had no description appended, just the part number (and therefore no spaces to delimit the split). This caused varInput(1) to error with "Subscript out of range". So I added the & " " in line 13 and took the space back out in line 17
This strikes me as terribly inelegant and I was wondering if anyone might have a better solution.
There is absolutely no timeline here because the inelegant solution worked and everybody is happy except for nit-picky me.
Jim
One of my clients' suppliers sent them a spreadsheet containing price increase data. For Ghu only knows what reason, they have a column with my client's part number and the supplier's description in the same cell.
No problem thinks I, I'll just suck it into Access as a table, Split that field in each record and put the bits where they belong. As below:
[CODE=vb]Private Sub btnFix_Click()
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strInput As String
Dim varInput As Variant
Set db = CurrentDb()
strSQL = "SELECT GoldacrePartNum ber, GasonDescriptio n from GasonNew"
Set rs = db.OpenRecordse t(strSQL, dbOpenDynaset)
Do Until rs.EOF
strInput = rs!GoldacrePart number & " "
varInput = Split(strInput, " ", 2)
rs.Edit
rs!GoldacrePart number = varInput(0)
rs!GasonDescrip tion = RTrim(varInput( 1))
rs.Update
rs.MoveNext
Loop
CleanUpAndLeave :
rs.Close
Set rs = Nothing
Set db = Nothing
DoCmd.Hourglass False
DoCmd.SetWarnin gs True
Exit Sub
End Sub[/CODE]
Well that worked fine except for the record which had no description appended, just the part number (and therefore no spaces to delimit the split). This caused varInput(1) to error with "Subscript out of range". So I added the & " " in line 13 and took the space back out in line 17
This strikes me as terribly inelegant and I was wondering if anyone might have a better solution.
There is absolutely no timeline here because the inelegant solution worked and everybody is happy except for nit-picky me.
Jim
Comment