DougTucker
Technical User
The following code is producing the error "Run time error 3265, Item not found in this collection". The comments sum up what the code is intended to do.
It produces the error when I pass the value through the function using the function RowsToColumns("Free Format Instructions"), and the variable in the code:
It works fine if I hard-code the column name:
I tried various syntax with and without quotes, brackets, etc. Any help would be appreciated. Here's the full function:
It produces the error when I pass the value through the function using the function RowsToColumns("Free Format Instructions"), and the variable in the code:
Code:
WholeString = rst!TextBlockName 'Column containing whole string
It works fine if I hard-code the column name:
Code:
WholeString = rst![Free Format Instructions]
I tried various syntax with and without quotes, brackets, etc. Any help would be appreciated. Here's the full function:
Code:
Function RowsToColumns(TextBlockName As String)
'Created by Doug Tucker on 7/20/2009
'This Function parses out individual rows in a single long text field
'of a specified table, and uses those rows to populate a series of columns
'in a table. All records from the array are translated into columns
'until the end of the array, then the function advances to the next row
'and repeats the process until reaching the end of the table.
'INPUT "TextBlockName" is the name of the column to be parsed.
'OUTPUT columns begin with "TextBlockName", plus a squential number "0-n"
'All output columns (0-n) must already exist in the table.
'
Dim mydb As Database 'Current database
Dim rst As Recordset 'Read into recordset
Dim WholeString As String 'Contents of entire cell (multi-rows)
Dim StringArray 'Array of rows of WholeString
Dim RowContents As String 'Contents of a single row of the cell
Dim Check, Counter 'Variables for Do-Loop
Dim strDelimiter As String
strDelimiter = Chr(13) & Chr(10) 'Line Break, new Line
Set mydb = CurrentDb
'<DEV> - Verify table name if this changes in production (drop references to "v2")
Set rst = mydb.OpenRecordset("Select * from [MyDataTable] order by [Record ID]")
'
rst.Edit
Do While Not rst.EOF 'Outer Loop; continue through entire table; exit if EOF
MoreRows = True: Counter = 0 'Initialize Variables
'WholeString = Nz(rst.Fields![TextBlockName], "") 'Column containing whole string
'<DEV NOTE: Try without "Nz"...
WholeString = rst!TextBlockName 'Column containing whole string
If WholeString = "" Then
MoreRows = False 'Stop immediately if array is empty
Exit Do 'get out of inner loop immediately
Else
StringArray = Split(WholeString, strDelimiter)
Do 'While MoreRows = True
'Do While more rows exist in the array (Counter < UBound(StringArray)
'Update data table with value from array
RowContents = StringArray(Counter)
rst.Edit
rst![TextBlockName & Counter] = RowContents
rst.Update
If Counter = UBound(StringArray) Then 'This is the last value of array
MoreRows = False
Else 'Set value of flag to false
Counter = Counter + 1
End If
'Exit Do 'Exit inner loop
Loop Until MoreRows = False
End If
rst.MoveNext 'Go to next row of recordset;
Loop 'Exit when EOF
'<DEV MESSAGE>
MsgBox "File is Done"
rst.Close 'Close the recordset
Set rst = Nothing 'Empty the recordset
End Function