Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help request: How to have objects move on Access form based on click 2

Status
Not open for further replies.

MyaCCt

MIS
May 14, 2014
21
0
0
US
Good morning Sunshine!

I dont know if that title does any justice to what I'm trying to do, but here goes... I have a form in Access 2010 that has fields that appear/disappear based on whether the user clicks a check box. If the checkbox, is clicked, the next option appears. I thought that was pretty fancy! :) But the user wants the bottom of the form to move up and down and the stuff on the form below to move up and down based on whether these check boxes have been marked. Is there a way to get these objects under the selection to move up and down based on the check, and if it is checked, to have the rest of the contents of the form move down to allow room for the option that appears when the box is checked?

As always, thank you for your time!
-MCC
 
Without seeing this my guess would be something like this. Tag all controls that you want to move using a character. I will use a question mark.
Code:
Private Sub CheckOne_Click()
  If CheckOne Then
    MoveControls "Down"
 Else
    MoveControls "Up"
  End If
End Sub
Public Sub MoveControls(Optional direction As String = "Down")
  Const AmountToMove = 0.25 ' inches
  Dim ctrl As Access.Control
  For Each ctrl In Me.Controls
    If ctrl.Tag = "?" Then
     If direction = "Down" Then
       ctrl.Top = ctrl.Top + InchesToTwips(AmountToMove)
     ElseIf direction = "Up" Then
       ctrl.Top = ctrl.Top - InchesToTwips(AmountToMove)
     End If
    End If
  Next ctrl
End Sub
Public Function InchesToTwips(inches As Double) As Long
  InchesToTwips = 1440 * inches
End Function
 
If you have some groups(s) of controls to move together up and down, you may consider placing them in a frame(s) (group box es). This way you need to move just one control – a frame – and all controls on that frame will move/appear/disappear. It is a lot easier to keep track of a few controls (frames) rather than 10’s of them.

Just an idea…


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Using the frame idea you could simplify the code. Add additional frames as needed.
Code:
Public Sub MoveControls(Optional direction As String = "Down")
  Const AmountToMove = 0.25 ' inches
  If direction = "Down" Then
   Frame1.Top = Frame1.Top + InchesToTwips(AmountToMove)
   'Frame2.Top = Frame2.Top + InchesToTwips(AmountToMove) 
 ElseIf direction = "Up" Then
  Frame1.Top = Frame1.Top - InchesToTwips(AmountToMove)
  'Frame2.Top = Frame2.Top - InchesToTwips(AmountToMove) 
 End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top