Dim lCurrentRow As Long[COLOR=Red], RowsMax As Long, RowsMin As Long[/COLOR]
Dim dWidth As Double
Option Explicit
Private Sub cmdPrev_Click()
' Show previous only if not already in first row:
If lCurrentRow > 6 Then
' Decrement row number:
lCurrentRow = lCurrentRow - 1
' Show contents of row in the form:
LoadRow
End If
End Sub
Private Sub cmdNext_Click()
' Increment row number:
lCurrentRow = lCurrentRow + 1
' Show contents of row in the form:
LoadRow
End Sub
Private Sub cmdDelete_Click()
Dim smessage As String
smessage = "Are you sure you want to delete " + Textitem.Text + "?"
If MsgBox(smessage, vbQuestion + vbYesNo, _
"Confirm Delete") = vbYes Then
' Delete current row
Rows(lCurrentRow).Delete
' Show contents of new current row in the form:
LoadRow
End If
End Sub
Private Sub cmdAdd_Click()
' Save form contents before changing rows:
SaveRow
' Clear the form for user to add new name:
LoadRow
' Set focus to Name textbox:
Textitem.SetFocus
End Sub
[COLOR=Red]Private Sub SpinButton1_SpinDown()
lCurrentRow = lCurrentRow + 1
If lCurrentRow > RowsMax Then lCurrentRow = RowsMin
LoadRow
End Sub
Private Sub SpinButton1_SpinUp()
lCurrentRow = lCurrentRow - 1
If lCurrentRow < RowsMin Then lCurrentRow = RowsMax
LoadRow
End Sub[/COLOR]
Private Sub cmdClose_Click()
Unload Me ' Close the form
End Sub
Private Sub LoadRow()
POnumber.Text = Cells(lCurrentRow, 20).Value
Textitem.Text = Cells(lCurrentRow, 2).Value
Supplier.Text = Cells(lCurrentRow, 3).Value
TextQty.Text = Cells(lCurrentRow, 4).Value
TextPpU.Text = Cells(lCurrentRow, 5).Value
Combcurruncy.Text = Cells(lCurrentRow, 6).Value
CombTVA.Text = Cells(lCurrentRow, 9).Value
TextDoO.Text = Cells(lCurrentRow, 10).Value
TextDoD.Text = Cells(lCurrentRow, 11).Value
CombDelivery.Text = Cells(lCurrentRow, 12).Value
TextDesc1.Text = Cells(lCurrentRow, 13).Value
CombPurchstype.Text = Cells(lCurrentRow, 14).Value
TextDescr2.Text = Cells(lCurrentRow, 15).Value
Comboorder.Text = Cells(lCurrentRow, 16).Value
Combproject.Text = Cells(lCurrentRow, 17).Value
TextFileRef.Text = Cells(lCurrentRow, 18).Value
TextNotes.Text = Cells(lCurrentRow, 19).Value
Pmtstatus.Text = Cells(lCurrentRow, 21).Value
Adddelivery.Text = Cells(lCurrentRow, 22).Value
End Sub
Private Sub SaveRow()
Cells(lCurrentRow, 20).Value = POnumber.Text
Cells(lCurrentRow, 2).Value = Textitem.Text
Cells(lCurrentRow, 3).Value = Supplier.Text
Cells(lCurrentRow, 4).Value = TextQty.Text
Cells(lCurrentRow, 5).Value = TextPpU.Text
Cells(lCurrentRow, 6).Value = Combcurruncy.Text
Cells(lCurrentRow, 9).Value = CombTVA.Text
Cells(lCurrentRow, 10).Value = TextDoO.Text
Cells(lCurrentRow, 11).Value = TextDoD.Text
Cells(lCurrentRow, 12).Value = CombDelivery.Text
Cells(lCurrentRow, 13).Value = TextDesc1.Text
Cells(lCurrentRow, 14).Value = CombPurchstype.Text
Cells(lCurrentRow, 15).Value = TextDescr2.Text
Cells(lCurrentRow, 16).Value = Comboorder.Text
Cells(lCurrentRow, 17).Value = Combproject.Text
Cells(lCurrentRow, 18).Value = TextFileRef.Text
Cells(lCurrentRow, 19).Value = TextNotes.Text
Cells(lCurrentRow, 21).Value = Pmtstatus.Text
Cells(lCurrentRow, 22).Value = Adddelivery.Text
End Sub
Private Sub UserForm1_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
[COLOR=Red]Private Sub UserForm_Initialize()
' Read initial values from Row 1:
RowsMax = Range("A" & Rows.Count).End(xlUp).Row
RowsMin = 6
lCurrentRow = RowsMin
LoadRow
End Sub[/COLOR]
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the close button!"
End If
End Sub
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
Me.Height = Me.Height * 0.11
Else
Me.Height = dWidth
End If
End Sub
Private Sub cmdClear_Click()
Textitem.Value = Null
Supplier.Value = Null
TextQty.Value = Null
TextPpU.Value = Null
Combcurruncy.Value = Null
CombTVA.Value = Null
TextDoO.Value = Null
TextDoD.Value = Null
CombDelivery.Value = Null
TextDesc1.Value = Null
CombPurchstype.Value = Null
TextDescr2.Value = Null
Comboorder.Value = Null
Combproject.Value = Null
TextFileRef.Value = Null
TextNotes.Value = Null
Adddelivery.Value = Null
Pmtstatus.Value = Null
End Sub