Solved Controlling ScrollBars on a subform

Local time
Today, 07:04
Joined
Feb 28, 2023
Messages
725
I think I probably have this as good as I can get it, but I wanted to ask here first since it isn't working as I expected.

I have a simple subform with two columns and several thousand records.

I want the subform to have a vertical scrollbar and no horizontal scrollbar.

I looked at these threads:


The subform originally was 5.25-inches wide and had horizontal and vertical scrollbars.

If I made the form 5.51 inches wide (the width of the form plus the width of the vertical scrollbars, it worked, but it was somewhat quirky... There are 13 records visible. If I clicked in Record 13 and pressed the down arrow, the vertical scrollbar appeared, but otherwise, it was not shown.

I tried ArnelGP's suggestion and if I set Me.Scrollbars = 0 in the subform's Form_Current event, when I click in the subform to make it current, the vertical scrollbar appears and the mouse scroll wheel works. Almost what I want, except the scrollbar doesn't appear until I click in the subform.

Adding Me.Scrollbars = 0 to the subform Form_Load or subform Form_Open event didn't do anything.

Also - Scrollbars = 0 is SUPPOSED to hide both scrollbars. Scrollbars = 1 (Horizontal) made a horizontal scrollbar appear when I clicked in the subform, but then it vanished if I tried to select it. Scrollbars = 2 vertical made the vertical scrollbar fade in and out. And Scrollbars = 3 made both of them fade in and out.

At this point, all I'm trying to do is have the vertical scrollbar visible in the subform BEFORE I actually click in the subform.

Thanks in advance!

Me.Scrollbars = 2
 
I think that's normal behavior that scrollbars don't show up until the control with large content gets the focus (you could check this by simply tabbing to the subform, instead of clicking on it). If you want the scrollbars to constantly show, you may have to use an API for that.
 
I want the subform to have a vertical scrollbar and no horizontal scrollbar.
Have to tried opening the form in design mode and just setting the Scroll Bars property to Vertical Only?
 
if you want to show 13 records visible, then the form will hide the scrollbar when you only have 12 records + 1 "new record (fathom record)
 
@theDBguy - Thanks, that gave me an idea, but it didn't work. In the main forms Form_Activate event, I tried adding Me.Subform.SetFocus, and in the subforms Form_GotFocus event, I tried adding Me.Scrollbars = 0 and Me.ScrollBars = 2, but it didn't work.

One thing I found: If I open the main form and click on the subform, I don't have scrollbars. If I click either column of the subform, the scrollbars don't appear. If I click either column in the first record of the subform, the scrollbars don't appear. If I click any record other than the first record of the subform, the scrollbars DO appear.

But I don't know any way (other than SendKeys) to activate this when the main form is opened.

@LarryE - yes, oddly, that works fine if I open the subform directly, but not if I open the main form with the subform included on it.

@arnelgp - understood, but that isn't the issue. The subform has several thousand records. The height of the subform on the main form only allows 13 records to be visible at one time.
 
In the main forms Form_Activate event, I tried adding Me.Subform.SetFocus, and in the subforms Form_GotFocus event, I tried adding Me.Scrollbars = 0 and Me.ScrollBars = 2, but it didn't work.

I have no problems with Scrollbars.

In a main form I use: HB_form.Scrollbars = 2.
in a sub form I use: HB_sub.Form.Scrollbars = 2.

Imb.
 
@Imb - where? I.e. for me it would be HB_Sub.Form.Scrollbars = 2. In the main form would this be in the Form_Open, Form_Activate, Form_Current event or somewhere else?
 
@Imb - where? I.e. for me it would be HB_Sub.Form.Scrollbars = 2. In the main form would this be in the Form_Open, Form_Activate, Form_Current event or somewhere else?
I usualy do it in the Open event of the (sub)form, after all controls are defined.
Then I do a Resize of the form, and depending of the number of records (continuous) or controls (unbound), the Scrollbars are defined.

Imb.
 
Solved - although the solution was weird:

As I said, specifying scrollbars in the subform Form_Open event doesn't work.

Specifying Me.Scrollbars = 2 or Me.Form.Scrollbars = 2 in the subforms Form Current event shows the scrollbar briefly, but then it disappears.

Specifying Me.Scrollbars = 0 or Me.Form.Scrollbars = 0 (None) in the Form Current even works, but only when I click other than the first record in the form (which makes it current ...)

What worked is calling the subform current event in the main form's Form_Activate event, i.e. in the subform, changing Private Sub Form_Current to Public Sub Form_Currrent and then:

Call Form_Subform.Form_Current

Where "Form_Subform" is the name as it appears in the VBE Class Objects list.

Thanks to all!
 
Just wanted to follow up - there is a slightly easier solution.

In the main form's Form_Activate() code, specifying:

Me.subformname.Form.Scrollbars = 0

works also and then I don't have to specify anything in the subform's Form_Current() event.

I'm not sure why it works with Scrollbars = 0 (None) and not with Scrollbars = 2 (vertical) or with the command not specified.

With Scrollbars = 2, the scrollbar didn't appear until I clicked in the form, but I think it only showed up then b/c I hadn't removed the subform's Form_Current() setting yet.
 

Users who are viewing this thread

Back
Top Bottom