I demonstrate this exact thing here. As @arnelgp stated, you can still trap the event in the form's class too.Follow up question if I may: triggering these 3 mouse events now calls the code in your class module bypassing any code in the form itself, correct? How does this impact other events (on_click etc..)? Must they all fall under the class module now or can they be coded in the main form?
If you want to practice. I would add some key down events too to make this user friendly. Still allow the user to drag and drop, but that is a little clunky. It is hard to actually position since it is not a true drag and drop. You do not see where it is before dropping. You should add events for arrow, down, left, right. Then if it is a right arrow nudge it right. Add a small increment to the x position. Same for the other arrows.My initial solution involved a traditional text box at first wherein the user just keyed in the distances from the top and left borders but the user wanted to drag/drop with their mouse and then use up down left right buttons to fine tune where everything sits.
Private DragBoxes As New Collection
Private Sub Form_Load()
Dim DB As DragBox
Dim ctr As Access.Control
For Each ctr In Me.Controls
If ctr.Tag = "DB" Then
Set DB = New DragBox
DB.Initialize ctr
DragBoxes.Add DB
End If
Next ctr
End Sub
you are Over complicating a simple "cheque" filling/printing?
just cut a paper with same size as your cheque.
print and adjust the position of the label/textbox
until you get it right.
you can use Report (one report for specific bank), can do?every bank has a few cheque formats
Where's the fun in thatyou can use Report (one report for specific bank), can do?
he is doing it in the Form.Where's the fun in that
you can use Report (one report for specific bank), can do?
Where's the fun in that
It looks like the OP is saving the results for each cheque type, so it's like the end-user designing the reports for you, without giving you the cheque books.
Who still writes cheques anyway?
he is doing it in the Form.
form coordinates does not translate to Paper (report) coordinate, or it is.
that part is more fun.
What are "cheques"?Who still writes cheques anyway?
count how many reports in this db alone.within each of these 18 there's a few different templates so we're looking at least 35 reports here
count how many reports in this db alone.
DCount("*", "MSysObjects", "Type=-32764")
Yes but since you are capturing events you will have to double up the event procedures. First you make a variable for each control type.Follow up question: can the class module work with more than one access control? The code you shared earlier only passes the label to the classmodule, what if i want to pass 4 more command buttons along with it?
I basically want to pass the label and its 4 neighboring arrow buttons to the class module
Once dragged, the neighboring arrows should move with reference to it
Private WithEvents mDragTextBox As Access.TextBox
---------------- Add another control type
Private WithEvents mCombo As Access.ComboBox
Public Sub Initialize(TheTextBox As Access.TextBox)
TheTextBox.OnMouseDown = "[Event Procedure]"
TheTextBox.OnMouseMove = "[Event Procedure]"
TheTextBox.OnMouseUp = "[Event Procedure]"
TheTextBox.OnKeyDown = "[Event Procedure]"
Set Me.DragTextBox = TheTextBox
End Sub
------------------------- Change to
Public Sub Initialize(TheControl As Access.Control)
TheControl.OnMouseDown = "[Event Procedure]"
TheControl.OnMouseMove = "[Event Procedure]"
TheControl.OnMouseUp = "[Event Procedure]"
TheControl.OnKeyDown = "[Event Procedure]"
Select case TheControl.controlType
case AcTextBox
set me.DragTextBox = theControl
case AcCombobox
Set Me.DragCombo = theControl
end select
End Sub
Option Compare Database
Option Explicit
Private WithEvents mDragTextBox As Access.TextBox
Private WithEvents mDragcommandbutton As Access.CommandButton
Dim MoveMe As Boolean
Dim InitX As Long
Dim InitY As Long
Dim DragX As Long
Dim DragY As Long
Private Sub mDragTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
Dim x As Long
Dim y As Long
Dim shiftSpeed As Integer
x = Me.DragTextBox.Left
y = Me.DragTextBox.Top
If Shift = acShiftMask Then
shiftSpeed = 100
Else
shiftSpeed = 10
End If
Select Case KeyCode
Case vbKeyUp
Me.DragTextBox.Top = y - shiftSpeed
Case vbKeyDown
Me.DragTextBox.Top = y + shiftSpeed
Case vbKeyRight
Me.DragTextBox.Left = x + shiftSpeed
Case vbKeyLeft
Me.DragTextBox.Left = x - shiftSpeed
End Select
End Sub
Private Sub mDragTextBox_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = acLeftButton And Shift = acCtrlMask Then
MoveMe = True
InitX = x
InitY = y
Else
MoveMe = False
End If
End Sub
Private Sub mDragTextBox_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If MoveMe = True Then
DragX = x
DragY = y
End If
End Sub
Private Sub mDragTextBox_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If MoveMe = True Then
With DragTextBox
.Left = .Left + DragX - InitX
.Top = .Top + DragY - InitY
End With
MoveMe = False
End If
End Sub
'------------------------------------------ Duplicate code
Private Sub mDragcommandbutton_KeyDown(KeyCode As Integer, Shift As Integer)
Dim x As Long
Dim y As Long
Dim shiftSpeed As Integer
x = Me.Dragcommandbutton.Left
y = Me.Dragcommandbutton.Top
If Shift = acShiftMask Then
shiftSpeed = 100
Else
shiftSpeed = 10
End If
Select Case KeyCode
Case vbKeyUp
Me.Dragcommandbutton.Top = y - shiftSpeed
Case vbKeyDown
Me.Dragcommandbutton.Top = y + shiftSpeed
Case vbKeyRight
Me.Dragcommandbutton.Left = x + shiftSpeed
Case vbKeyLeft
Me.Dragcommandbutton.Left = x - shiftSpeed
End Select
End Sub
Private Sub mDragcommandbutton_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = acLeftButton And Shift = acCtrlMask Then
MoveMe = True
InitX = x
InitY = y
Else
MoveMe = False
End If
End Sub
Private Sub mDragcommandbutton_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If MoveMe = True Then
DragX = x
DragY = y
End If
End Sub
Private Sub mDragcommandbutton_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If MoveMe = True Then
With Dragcommandbutton
.Left = .Left + DragX - InitX
.Top = .Top + DragY - InitY
End With
MoveMe = False
End If
End Sub
'--------------------------------------------------------------------------------------
Public Sub Initialize(TheControl As Access.Control)
TheControl.OnMouseDown = "[Event Procedure]"
TheControl.OnMouseMove = "[Event Procedure]"
TheControl.OnMouseUp = "[Event Procedure]"
TheControl.OnKeyDown = "[Event Procedure]"
Select Case TheControl.ControlType
Case acTextBox
Set Me.DragTextBox = TheControl
Case acCommandButton
Set Me.Dragcommandbutton = TheControl
End Select
End Sub
Public Property Get DragTextBox() As Access.TextBox
Set DragTextBox = mDragTextBox
End Property
Public Property Set DragTextBox(ByVal objNewValue As Access.TextBox)
Set mDragTextBox = objNewValue
End Property
Public Property Get Dragcommandbutton() As Access.CommandButton
Set Dragcommandbutton = mDragcommandbutton
End Property
Public Property Set Dragcommandbutton(ByVal objNewValue As Access.CommandButton)
Set mDragcommandbutton = objNewValue
End Property
This is exactly what I was talking about earlier. It works for our needs; although in our case, we were using it for Award Certificates. Cheers!I would think you could still do this dynamically for each check instead of hard coding checks. I would think you could have a single Check report. Then have a table that stores the positions of each control and if that control is visible or not. Then when you load that check for that bank it positions the controls dynamically in the on open event. This way to add a new report you just add a record in the table instead of redesigning. Now you may be able to use this dynamic form to then write to the table the correction positions after moving them to where you want. Not sure if that is doable. Because currently (if I understand), if you move these controls around they do not persist. Next time you print you have to do it all over again.