I've been trying to create sort of a sidebar menu that would pop in when you click on a button for quite a bit now and for some reason, I am unable to do it. When I save the code and open the form to test, the "side menu" (which is another form) can be seen instead of being out of the area that you can see. Imgur preview.
The list of forms is pretty messy, but the only ones actually used in the question are the "Menu" and "TestFormFormForm" (don't ask about the name). The code I am using is as follows.
Option Compare Database
Private Sub Command2_Click()
Dim x As Integer
x = 0
Do
DoEvents
Menu.Left = Menu.Left - 100
timeout (0.0075)
x = x + 1
Loop Until x = 50
End Sub
Private Sub Form_Load()
Me.ScrollBars = 0
Menu.Left = Me.Width + 1000
Menu.Move _
Left:=Me.Width + 1000, Top:=500
End Sub
Sub timeout(duration_ms As Double)
Start_Time = Timer
Do
DoEvents
Loop Until (Timer - Start_Time) >= duration_ms
End Sub
I have also tried using Me.WindowWidth = XYZ until I realized that WindowWidth is read-only.
Following works for me:
set database option for Overlapping Windows
set the main form AutoResize property to No and sized so the right edge covers part of the right edge of the subform to account for vertical scroll bar space
set ScrollBars property to neither
set the subform width as small as possible (must be at least width of its controls) and Visible property to No
eliminate form Load event
use Toggle instead of Command button
experiment with various combinations of constants in code
Revised code:
Private Sub Toggle4_Click()
Dim x As Integer
Me.Menu.Visible = True
Do
DoEvents
Me.Menu.Width = Me.Menu.Width + IIf(Me.Toggle4, 200, -200)
Me.Menu.Left = Me.Menu.Left - IIf(Me.Toggle4, 200, -200)
Me.Toggle4.Left = Me.Toggle4.Left - IIf(Me.Toggle4, 200, -200)
timeout (0.01)
x = x + 1
Loop Until x = 10
Me.Menu.Visible = Me.Toggle4
End Sub