Vigilante001
A Jolly Fellow...
- Local time
- Today, 06:32
- Joined
- May 16, 2008
- Messages
- 28
Hello,
?:: Are there instances where the ColumnWidth property of a textbox & combobox cannot be changed through VBA?
I have a form with two buttons (save & load) and a sub-form (30+ columns). When the save button is pressed, I have a VBA sub pull the name, sequence, and width of all rows and store them in a table. The code is below:
Then, I resize/reorder the columns in the sub-form. When I press load, another sub applies the saved settings back to the sub-form columns, searching for textboxes & comboboxes. See here:
The sequence part works for all columns, but the ColumnWidth works for all columns but five. Four of them are multicolumn comboboxes, and the other is an Autonumber. This works for other mulitcomboboxes, and I wasn't sure if there were instances where the ColumnWidth property cannot be changed.
Thanks
-V
?:: Are there instances where the ColumnWidth property of a textbox & combobox cannot be changed through VBA?
I have a form with two buttons (save & load) and a sub-form (30+ columns). When the save button is pressed, I have a VBA sub pull the name, sequence, and width of all rows and store them in a table. The code is below:
Code:
Private Sub btnSaveRememberFieldParameters_Click()
'****************************************************************************
'Ensure table is present
'****************************************************************************
Dim tblDef As TableDef
Dim SQL As String
Dim SQL2 As String
Dim varCreateTable As String
varCreateTable = "Create"
'Look for tblUserOptions
For Each tblDef In CurrentDb.TableDefs
If tblDef.Name = "tblUserOptions" Then
varCreateTable = "Flush"
End If
Next tblDef
'If table was found...flush values. If not found, create it.
If varCreateTable = "Flush" Then
If MsgBox("This action will replace your prior saved settings. Proceed?", vbYesNo, "Confirm Overwrite") = vbYes Then
'Flush user values
SQL = "DELETE * FROM tblUserOptions WHERE OptionCategory = 'FormWidthSettings';"
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL SQL
DoCmd.SetWarnings (WarningsOn)
Else
Exit Sub
End If
End If
'****************************************************************************
'Record the Type, Name, Width, and Order of all objects
'****************************************************************************
Dim ctlType As String
Dim ctlName As String
Dim ctlWidth As String
Dim ctlSequence As String
'Run through all objects
For x = 0 To Forms![DailyActivityES&S]!DailyActivitySubform.Controls.Count - 1
'These properties apply to all controls
ctlType = TypeName(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x))
ctlName = Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x).Name
'These properties apply to only TextBox & ComboBox controls
If TypeName(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x)) = "TextBox" Then
ctlWidth = Nz(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x).ColumnWidth, "")
ctlSequence = Nz(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x).ColumnOrder, "")
SQL = "INSERT INTO tblUserOptions (OptionCategory, OptionCategoryDate, ControlType, ControlName, ControlWidth, ControlSequence) " & _
"VALUES ('FormWidthSettings', '" & Format$(Date, "mm/dd/yy") & "', '" & ctlType & "', " & _
"'" & ctlName & "', " & _
"'" & ctlWidth & "', " & _
"'" & ctlSequence & "');"
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL SQL
DoCmd.SetWarnings (WarningsOn)
ElseIf TypeName(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x)) = "ComboBox" Then
ctlWidth = Nz(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x).ColumnWidth, "")
ctlSequence = Nz(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x).ColumnOrder, "")
SQL = "INSERT INTO tblUserOptions (OptionCategory, OptionCategoryDate, ControlType, ControlName, ControlWidth, ControlSequence) " & _
"VALUES ('FormWidthSettings', '" & Format$(Date, "mm/dd/yy") & "', '" & ctlType & "', " & _
"'" & ctlName & "', " & _
"'" & ctlWidth & "', " & _
"'" & ctlSequence & "');"
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL SQL
DoCmd.SetWarnings (WarningsOn)
Else 'Any other control type gives blanks for ControlWidth and Sequence
SQL = "INSERT INTO tblUserOptions (OptionCategory, OptionCategoryDate, ControlType, ControlName, ControlWidth, ControlSequence) " & _
"VALUES ('FormWidthSettings', '" & Format$(Date, "mm/dd/yy") & "', '" & ctlType & "', " & _
"'" & ctlName & "', " & _
"'', " & _
"'');"
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL SQL
DoCmd.SetWarnings (WarningsOn)
End If
Next x
Forms!frmUserOptions!txtRememberFieldParametersSaved = "Last saved on: " & Nz(DLookup("OptionCategoryDate", "tblUserOptions", "OptionCategory = 'FormWidthSettings'"), "[Not Saved Yet]")
Forms!frmUserOptions!btnLoadRememberFieldParameters.Visible = True
End Sub
Code:
Private Sub btnLoadRememberFieldParameters_Click()
'****************************************************************************
'Apply object values to the new form
'****************************************************************************
If MsgBox("This action will replace your prior saved settings. Proceed?", vbYesNo, "Confirm Overwrite") = vbYes Then
For x = 0 To Forms![DailyActivityES&S]!DailyActivitySubform.Controls.Count - 1
ctlType = TypeName(Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x))
ctlName = Forms![DailyActivityES&S]!DailyActivitySubform.Controls(x).Name
If ctlType = "TextBox" Then
ctlWidth = DLookup("ControlWidth", "tblUserOptions", "ControlName = '" & ctlName & "'")
ctlSequence = DLookup("ControlSequence", "tblUserOptions", "ControlName = '" & ctlName & "'")
If IsNull(DLookup("ControlName", "tblUserOptions", "ControlName = '" & ctlName & "'")) = False Then
'Debug.Print ctlName
MsgBox (ctlName & vbCrLf & vbCrLf & "Width Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnWidth & vbCrLf & "Width Future: " & ctlWidth & vbCrLf & vbCrLf & "Sequence Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnOrder & vbCrLf & "Sequence Future: " & ctlSequence)
Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnWidth = ctlWidth
Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnOrder = ctlSequence
MsgBox (ctlName & vbCrLf & vbCrLf & "Width Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnWidth & vbCrLf & "Width Future: " & ctlWidth & vbCrLf & vbCrLf & "Sequence Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnOrder & vbCrLf & "Sequence Future: " & ctlSequence)
End If
End If
If ctlType = "ComboBox" Then
ctlWidth = DLookup("ControlWidth", "tblUserOptions", "ControlName = '" & ctlName & "'")
ctlSequence = DLookup("ControlSequence", "tblUserOptions", "ControlName = '" & ctlName & "'")
If IsNull(DLookup("ControlName", "tblUserOptions", "ControlName = '" & ctlName & "'")) = False Then
'Debug.Print ctlName
MsgBox (ctlName & vbCrLf & vbCrLf & "Width Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnWidth & vbCrLf & "Width Future: " & ctlWidth & vbCrLf & vbCrLf & "Sequence Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnOrder & vbCrLf & "Sequence Future: " & ctlSequence)
Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnWidth = ctlWidth
Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnOrder = ctlSequence
MsgBox (ctlName & vbCrLf & vbCrLf & "Width Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnWidth & vbCrLf & "Width Future: " & ctlWidth & vbCrLf & vbCrLf & "Sequence Current: " & Forms![DailyActivityES&S]!DailyActivitySubform.Controls(ctlName).ColumnOrder & vbCrLf & "Sequence Future: " & ctlSequence)
End If
End If
Next x
Else
Exit Sub
End If
' Here I am!
End Sub
Thanks
-V