bendataclear
bendataclear

Reputation: 3850

Access - Form or control width doesn't update

I am trying to set listbox column widths based on the current size of the listbox, I've set it to use the Listbox.Width property but this never seems to update, it stays at the value set in design mode.

Even created a new form with a resize event as below:

Private Sub Form_Resize()
    Text0 = CStr(Me.Width) & " - " & CStr(Rnd())
End Sub 

And the width stays static as I resize it (the event is certainly firing as the random value changes).

Is this a know problem with Access and if so are there any work-arounds?

How can I get the current width of the control or form?

Upvotes: 1

Views: 1236

Answers (1)

bendataclear
bendataclear

Reputation: 3850

I found a messy work around (but I'm still open to suggestions for a better one).

The only property that seems to change on resize is the Form.InsideWidth.

At form load I save the difference between the Listboxes width and the inside width:

Private Sub Form_Load()
    p_ListToWindowDiff = Me.InsideWidth - Listbox1.Width
End Sub

Then when resized I use this to get the new listbox width:

NewListWidth = Me.InsideWidth - p_ListToWindowDiff

Upvotes: 1

Related Questions