Can VBA change Split Form Size?

B

Brad

I just started to experiment with split forms today. I would like to know if
it is possible to use VBA to change how the form is split between the upper
and lower parts. An example would be most appreciated.

Thanks,
Brad
 
D

Dale Fye

Brad,

Before we had split forms, I did something similar to what you are talking
about, but it required a lot of code. Basically, here is what I did.

I put two subforms on my main form, the one on the top was in form view, the
one on the bottom was in datasheet view.

I added a rectangle between the two subforms that ran the width of the form,
and was about .05" high. I used the rectangle because it had mouse events
associated with it.

I then added code to the forms code module:
1. Declared variable dblStartY as Double in the general section
2. Added code to the MouseDown, MouseUp and MouseMove events of the
divider. The following code code is from a sample I just did where I put two
boxes (box_top and box_bottom) on my form.

Private Sub box_Divider_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)

'need to set this to identify the amount of shift
dblStartY = Y

End Sub

Private Sub box_Divider_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)

Dim dblDelta As Double

If dblStartY = 0 Then Exit Sub

dblDelta = (dblStartY - Y)

'These are arbitrary values that limit the sizing.
'dividing line can only move within the 1" and 3" vertical range
'this code moves the divider, grows/shrinks the top box, and moves
'the top and adjusts the height of the bottom box accordingly
If (Me.box_Divider.Top - dblDelta) / 1440 > 1 And _
(Me.box_Divider.Top - dblDelta) / 1440 < 3 Then
Me.box_Top.Height = Me.box_Top.Height - dblDelta
Me.box_Divider.Top = Me.box_Divider.Top - dblDelta
Me.box_Bottom.Top = Me.box_Bottom.Top - dblDelta
Me.box_Bottom.Height = Me.box_Bottom.Height + dblDelta
End If

End Sub

Private Sub box_Divider_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)

'sets dblStartY to zero so that the divider doesn't
'move every time you slide your mouse over it
dblStartY = 0

End Sub

With this method, you will have to add code to the current event of both
subforms so that the record with the focus in the other subform matches the
record with the focus in the current form.

Hope this helps.
 
B

Brad

Thanks for the help!
--
Brad


AccessVandal via AccessMonster.com said:
You cannot change the properties at runtime as you'll have to go into design
view to modify the properties.

acDataSheetOnBottom
acDataSheetOnLeft
acDataSheetOnRight
acDataSheetOnTop

example: Forms!YourFormName.SplitFormOrientation = acDataSheetOnLeft

I don't know the constant number but it should be somethinglike 0,1,2,3.
Check out 2007 Help.

But you'll not be able to modify the constant from your form but you can
modify it if you create a code from another form. Create another with command
buttons to try it out.

Private Sub Command0_Click()
Docmd.openform "YourFormName", acDesign,,,,acHidden
'You may or may not want to save the form
Docmd.save acForm, "YourFormName"
Forms!YourFormName..SplitFormOrientation = acDataSheetOnLeft
Docmd.openform "YourFormName", acNormal,,,,acWindowNormal
End Sub

It may not be a solution, but you give the idea. Test with 2007 SP1.


--
Please Rate the posting if helps you.



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top