Graham:
Thank you for that suggestion. I've implemented it and it works.
You're correct, it is a string with embedded VbCrLf characters.
What I was wondering was if there was a way to simply cram the
entire thing into an ADO recordset. I have a vague recollection
of doing something like that with Access 97 when ADO was first
being used, but couldn't find the code. (It probably doesn't exist)
What I'm doing is reading the ColumnOrder, ColumnHidden and
ColumnWidth values for all the controls of a datasheet and dumping
them into the Registry. Another function pulls out the blob and
processes it, reapplying the user's column settings.
I have to do this because we've gone to a new-client-file update
system that is pushing out a new copy of their MDB file daily. Users
started to complain that their datasheets weren't "remembering"
the previous day's settings. This code works pretty slick, though
there might be some caveat I haven't thought of.
If anyone has any advice for things to watch out for when mucking
with datasheet columns in code, I'd be glad to listen.
--
Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast
On Error GoTo Err_Handler
Dim ctl As Control
Dim strBlob As String
Dim strColumns() As String
Dim strColOrdered() As String
Dim intColumns As Integer
Dim intColumn As Integer
Dim strValues() As String
'Dim intValue As Integer
On Error Resume Next
strBlob = GetSetting(gcstr_WebErrCode, "Column_Settings", frm.Name, "")
If strBlob <> "" Then
strColumns = Split(strBlob, vbCrLf)
' Have to resort the list according to ordinal number
Call GetOrderedColumns(strBlob, strColumns)
intColumns = UBound(strColumns) - 1
If intColumns <> 0 Then
' The first column (0) is for RecCount and shouldn't be touched.
' Start with the first table column, ordinal position = 1
For intColumn = 1 To intColumns
strValues = Split(strColumns(intColumn), ":")
Set ctl = frm.Controls(strValues(0))
ctl.ColumnOrder = CInt(strValues(1))
ctl.ColumnHidden = CBool(strValues(2))
ctl.ColumnWidth = CLng(strValues(3))
Next
End If
End If
Exit_Here:
Exit Sub
Err_Handler:
'LogErrorToTable Err.Number, Err.Description, "basUserColumnSetup", "LoadUserColumnSetup", Erl
Resume Next
End Sub
Private Sub GetOrderedColumns(ByVal strData As String, ByRef strColumns() As String)
On Error Resume Next
Dim strTemp() As String
Dim intCols As Integer
Dim intCol As Integer
Dim intCurr As Integer
Dim strValues() As String
strTemp = Split(strData, vbCrLf)
intCols = UBound(strTemp) - 1
ReDim strColumns(intCols)
For intCol = 0 To intCols - 1
For intCurr = 0 To intCols
strValues = Split(strTemp(intCurr), ":")
If CInt(strValues(1)) = intCol Then
strColumns(intCol) = strTemp(intCurr)
Exit For
End If
Next
Next
End Sub
Public Sub SaveUserColumnSetup(ByRef frm As Form)
On Error GoTo Err_Handler
Dim ctl As Control
Dim strBlob As String
For Each ctl In frm.Controls
If ctl.ControlType <> acLabel Then
strBlob = strBlob & ctl.Name & ":" & ctl.ColumnOrder & ":" & ctl.ColumnHidden & ":" & ctl.ColumnWidth &
vbCrLf
End If
Next
SaveSetting gcstr_WebErrCode, "Column_Settings", frm.Name, strBlob
Exit_Here:
Exit Sub
Err_Handler:
'LogErrorToTable Err.Number, Err.Description, "basUserColumnSetup", "SaveUserColumnSetup", Erl
Resume Next
End Sub