-
I posted this question before and got some help, but there
is just one thing that's giving me a BIG problem, and that
is... the form will not scroll!!!
The problem is that data at the bottom is not scrolled into
view. How do i achieve this ?
I would prefer to display the data on a form and not a DBGrid
p.s. How do I post the code like others with colours &
indent ?
here is the code....
Sub Scroll()
Dim vPos As Integer
Me.Cls
FontSize = 8
x = CurrentX
y = CurrentY
CurrentX = 300
CurrentY = y
For vPos = m_intLastPos To 100
While Not rst.EOF
Print rst!recno
CurrentY = y
CurrentX = 1600
Print rst!ItemNum
CurrentY = y
CurrentX = 3100
Print Format(rst!QtyRecvd, "###,##0")
CurrentY = y
CurrentX = 4600
Print rst!Descrip
CurrentY = y
CurrentX = 8100
Print Format(rst!unitprice, "##,###,##0.00")
CurrentY = y
CurrentX = 9600
value = rst!QtyRecvd * rst!unitprice
runtot = runtot + value
Print Format(value, "##,###,##0.00")
y = CurrentY
CurrentX = 300
rst.MoveNext
Wend
Next
m_intLastPos = VScroll1.value
' print total at end of report
If runtot > 0 Then
FontBold = True
FontUnderline = True
CurrentX = 8100
CurrentY = CurrentY + 500
y = CurrentY
Print "GRAND TOTAL"
CurrentX = 9600
CurrentY = y
Print Format(runtot, "##,###,##0.00")
FontBold = False
FontUnderline = False
Else
NothingFound
End If
Else
NothingFound
End If
End Sub
-
Too scroll a Form, use the following code. Add an HScroll and a VScroll.
Code:
Dim VPos As Integer
Dim HPos As Integer
Private Sub Form_Load()
'Change the following numbers to the Full height and width of your Form
intFullHeight = 8000
intFullWidth = 8000
'This is the how much of your Form is displayed
intDisplayHeight = Me.Height
intDisplayWidth = Me.Width
With VScroll1
.Height = Me.ScaleHeight
.Min = 0
.Max = intFullHeight - intDisplayHeight
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
With HScroll1
.Width = Me.ScaleWidth
.Min = 0
.Max = intFullWidth - intDisplayWidth
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
End Sub
Sub ScrollForm(Direction As Byte)
Dim CTL As Control
'Scroll Vertically
If Direction = 0 Then
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.Y1 = CTL.Y1 + VPos - VScroll1.Value
CTL.Y2 = CTL.Y2 + VPos - VScroll1.Value
Else
CTL.Top = CTL.Top + VPos - VScroll1.Value
End If
End If
Next
VPos = VScroll1.Value
Else
'Scroll Horizontally
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.X1 = CTL.X1 + HPos - HScroll1.Value
CTL.X2 = CTL.X2 + HPos - HScroll1.Value
Else
CTL.Left = CTL.Left + HPos - HScroll1.Value
End If
End If
Next
HPos = HScroll1.Value
End If
End Sub
Private Sub HScroll1_Change()
ScrollForm 1
End Sub
Private Sub HScroll1_Scroll()
ScrollForm 1
End Sub
Private Sub VScroll1_Change()
ScrollForm 0
End Sub
Private Sub VScroll1_Scroll()
ScrollForm 0
End Sub
To make your code in colours, inclose it in code brackets.
[code]
MyCodeHere
[/code]
-
Thanks for your quick reply Megatron, but I already have
something similar to that....
This is what I have
[code]
Private Sub Form_Load()
frmPrtToScr.BackColor = &HFFFFFF
VScroll1.Max = 100
VScroll1.LargeChange = 5
VScroll1.SmallChange = 1
runtot = 0
If frmPrtOptions.optPrt.value = True Then
PrtReport
ElseIf frmPrtOptions.optScr.value = True Then
Call Scroll
End If
End Sub
Private Sub Form_Resize()
With VScroll1
.Top = 0
.Height = ScaleHeight
.Left = ScaleWidth - .Width
End With
End Sub
Private Sub VScroll1_Change()
Call Scroll
End Sub
Private Sub VScroll1_KeyUp(KeyCode As Integer, Shift As Integer)
Call Scroll
End Sub
Private Sub VScroll1_KeyDown(KeyCode As Integer, Shift As Integer)
Call Scroll
End Sub
Sub Scroll()
Dim vPos As Integer
Me.Cls
FontSize = 8
x = CurrentX
y = CurrentY
CurrentX = 300
CurrentY = y
rst.MoveFirst
If blank = False Then
For vPos = m_intLastPos To 100
While Not rst.EOF
Print rst!recno
CurrentY = y
CurrentX = 1600
Print rst!ItemNum
CurrentY = y
CurrentX = 3100
Print Format(rst!QtyRecvd, "###,##0")
CurrentY = y
CurrentX = 4600
Print rst!Descrip
CurrentY = y
CurrentX = 8100
Print Format(rst!unitprice, "##,###,##0.00")
CurrentY = y
CurrentX = 9600
value = rst!QtyRecvd * rst!unitprice
runtot = runtot + value
Print Format(value, "##,###,##0.00")
y = CurrentY
CurrentX = 300
rst.MoveNext
Wend
Next
'print report total
If runtot > 0 Then
FontBold = True
FontUnderline = True
CurrentX = 8100
CurrentY = CurrentY + 500
y = CurrentY
Print "GRAND TOTAL"
CurrentX = 9600
CurrentY = y
Print Format(runtot, "##,###,##0.00")
FontBold = False
FontUnderline = False
Else
NothingFound
End If
Else
NothingFound
End If
m_intLastPos = VScroll1.value
End Sub
[Edited by yenni on 11-15-2000 at 06:41 PM]
-
Cant you just make everything you want to scroll in a frame, and then put to the scroll event of the scrollbar something like this:
frame1.top = 0 - vscroll1.value
When min of vscroll1 is 0 and max is the height of the frame.
Just a suggestion, may not work...
-JR-
-
So how do you post code so it looks correct in the forums?
-
-
If I use a frame, will I be able to scroll the frame so the
text at the bottom will come into view?
-
Info...
Okay, so you make a frame inside a form, that preferrably meets the width of the window and the height is however much you want to make of it. Then you put in your contents, and leave the frame to a height so that it holds all the controls ya have. Then you resize the form (not the frame) to whatever height you want it to be and add a scrollbar OUTSIDE the frame (on the form). You can put it anywhere, and it CAN be a vertical or a horizontal one, though in my example I would make a vertical one. Then you set the Min value of the scrollbar to 0 and in the Resize event of the form, put:
VScroll1.Max = Frame1.Height / 2
Then in the Change event of the scrollbar, put:
Frame1.Top = 0 - VScroll1.Value
That should do it and is pretty simple. Cool. This is like the first time in here when I'm not asking a question... :)
-JR-