SparklySpartan
New member
- Local time
- Today, 17:56
- Joined
- Feb 25, 2025
- Messages
- 22
Hi Everyone,
I wanted to pick your brains if you don't mind on an issue I'm having with one of my forms. A key characteristic of the form I'm creating is that it will conditionally show / hide / resize / relabel columns based on data that gets passed to one of it's subroutines. Any help or insights you could provide would be appreciated. I'm especially curious how others have tackled implementing this same kind of behavior in their forms, so please feel free to share your solutions on this thread.
The subroutine I've created to do this is called Change_Columns
I'm completely open and welcome to code criticism and being taught a better way to do this by the way, but this is what I've devised at the moment.
First, I hide all of the columns (my Set_Column_Width and Set_Column_Visibility subs modify the properties of both the fields named and their corresponding headers). I have to hide all of the columns before expanding them to avoid the error that goes along the lines of "You can't increase the size of this control because it would be too big to fit in the form."
After hiding every column, I go through the controls a second time and re-enable the ones whose names are mentioned in the array I pass this subroutine. While I'm at it, I set the widths of the enabled columns to the desired widths and the captions to the desired captions.
My final step is to set the description field's (this is labeled "Task" in the screenshot below) width to whatever amount is left according to a variable of mine keeping track of the width I've used and the forms .InsideWidth property. Some might ask why I didn't just set that field as stretch across the top. I did try that, but it seemed to behave weirdly and inconsistently, so I opted to explicitly set the width of this column myself.
This system seems to work fine except for one weird visual glitch that happens only when you open the database for the first time. Every time I first open the database and switch to this tab for the first time, I see this weird gap that by my understanding of my code should not be there.
(Also note the columns labeled "Type" and "Author", the dropdown whose value is "Standard" is supposed to be directly underneath the "Type" column, and field with my name should be directly underneath the "Author" column, which has also been pushed off screen because of this empty space in the column headers)
I should mention that this form's on load event runs the above Change_Columns subroutine and passes it a valid array of column names.
It gets weirder. When I do something to resize the screen a bit like hit F11 twice, or temporarily making access a smaller window then going back to a fully sized window, this weird visual glitch magically goes away... the gap disappears and the fields and column headers are all once-again aligned like they should be.
I'm just plain confused about why this happens. I was curious on if anyone ran into similar weird visual artifacts like this in their projects and found some way to stop them from occurring in their code.
I thought the issue had something to do with padding, which is supposed to be zero for all of the controls, so I added the following loop to the end of my subroutine to check:
Any insights as to what this is, why it happens, why it only happens the first time I open the DB, and how I might fix it would be greatly appreciated.
Thanks in advance for your time and thoughts, hope this sparks an interesting discussion!
I wanted to pick your brains if you don't mind on an issue I'm having with one of my forms. A key characteristic of the form I'm creating is that it will conditionally show / hide / resize / relabel columns based on data that gets passed to one of it's subroutines. Any help or insights you could provide would be appreciated. I'm especially curious how others have tackled implementing this same kind of behavior in their forms, so please feel free to share your solutions on this thread.
The subroutine I've created to do this is called Change_Columns
Code:
Public Sub Change_Columns(ByRef column_info() As String)
' Column info is a 2 dimensional array with 3 rows
' row 1: Field Names
' row 2: Desired Widths for Columns (corresponding postions to row 1)
' row 3: Desired column names, if empty, default to captions already put there
Dim ctrl As Control
Dim column_included As Boolean
Dim i As Integer
Dim used_up_width As Double: used_up_width = 0
For Each ctrl In Section(acDetail).controls
Call Set_Column_Visibility(ctrl.Name, False)
Call Set_Column_Width(ctrl.Name, 0)
Next ctrl
For Each ctrl In Section(acDetail).controls
For i = 1 To UBound(column_info, 2)
If column_info(1, i) = ctrl.Name Then
Call Set_Column_Visibility(ctrl.Name, True)
If ctrl.Name <> "Description" Then
Call Set_Column_Width(ctrl.Name, CDbl(column_info(2, i)))
used_up_width = used_up_width + column_info(2, i)
End If
Call Set_Column_Caption(ctrl.Name, column_info(3, i))
Exit For
End If
Next i
Next ctrl
' Set description column to be equal to the remaining space in twips
Call Set_Column_Width("Description", Me.InsideWidth - used_up_width)
End Sub
I'm completely open and welcome to code criticism and being taught a better way to do this by the way, but this is what I've devised at the moment.
First, I hide all of the columns (my Set_Column_Width and Set_Column_Visibility subs modify the properties of both the fields named and their corresponding headers). I have to hide all of the columns before expanding them to avoid the error that goes along the lines of "You can't increase the size of this control because it would be too big to fit in the form."
After hiding every column, I go through the controls a second time and re-enable the ones whose names are mentioned in the array I pass this subroutine. While I'm at it, I set the widths of the enabled columns to the desired widths and the captions to the desired captions.
My final step is to set the description field's (this is labeled "Task" in the screenshot below) width to whatever amount is left according to a variable of mine keeping track of the width I've used and the forms .InsideWidth property. Some might ask why I didn't just set that field as stretch across the top. I did try that, but it seemed to behave weirdly and inconsistently, so I opted to explicitly set the width of this column myself.
This system seems to work fine except for one weird visual glitch that happens only when you open the database for the first time. Every time I first open the database and switch to this tab for the first time, I see this weird gap that by my understanding of my code should not be there.
(Also note the columns labeled "Type" and "Author", the dropdown whose value is "Standard" is supposed to be directly underneath the "Type" column, and field with my name should be directly underneath the "Author" column, which has also been pushed off screen because of this empty space in the column headers)
I should mention that this form's on load event runs the above Change_Columns subroutine and passes it a valid array of column names.
It gets weirder. When I do something to resize the screen a bit like hit F11 twice, or temporarily making access a smaller window then going back to a fully sized window, this weird visual glitch magically goes away... the gap disappears and the fields and column headers are all once-again aligned like they should be.
I'm just plain confused about why this happens. I was curious on if anyone ran into similar weird visual artifacts like this in their projects and found some way to stop them from occurring in their code.
I thought the issue had something to do with padding, which is supposed to be zero for all of the controls, so I added the following loop to the end of my subroutine to check:
Code:
For Each ctrl In Section(acDetail).controls
ctrl.LeftPadding = 0
ctrl.RightPadding = 0
Next ctrl
Any insights as to what this is, why it happens, why it only happens the first time I open the DB, and how I might fix it would be greatly appreciated.
Thanks in advance for your time and thoughts, hope this sparks an interesting discussion!