[ superr @ 03.08.2015. 01:11 ] @
pozdrav, na userformi imam dva problematična textboxa: txbŠirina i txbVisina gde bi vrednosti trebale biti prihvaćene ako su između 300 i 6000 e sada je problem ako se bilo koja vrednost obriše da li slučajno ili namerno ostali kodovi vezani za ova polja "pucaju". Da li se ta polja mogu zaštiti od "select & delete")?Probavao sam nešto na exit ali čim obrišem vrednost iz textbox polja javlja se problem. Evo malo koda da bude jasnije:

Private Sub txbŠirina_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txbŠirina.Value < 300 Or txbŠirina.Value > 6000 Then
MsgBox "Invalid input. Please enter a number b/w 100 and 6000.", vbCritical
Cancel = True
Else
Cancel = False
End If
End Sub
[ Jpeca @ 12.08.2015. 14:32 ] @
Ne znam čemu služe ovi Cancel flagovi. Verujem da je dovoljno da postaviš neku vrednost text boxa nakon validacije (Null ili neku konkretnu dozvoljenu vrednost). Ja bih proceduru validacije izdvojio i onda pozivao iz Exit za oba text boxa

Code:
Private Sub txtSirina_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Validate
End Sub

Private Sub txtVisina_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Validate
End Sub

Private Sub Validate()
' Procedura za validaciju vrednosti text boxa
 If TypeName(Me.ActiveControl) = "TextBox" Then
        With Me.ActiveControl
            If Not IsNumeric(.Value) Or (IsNumeric(.Value) And (.Value < 300 Or .Value > 6000)) Then
                MsgBox "Invalid input. Please enter a number b/w 300 and 6000.", vbCritical
                .Value = vbNullString
            End If
        End With
 End If
End Sub
[ superr @ 14.12.2015. 17:13 ] @
Peco hvala ti puno na pomoći ali imam problem i dalje... mislim da bi pomoglo ako bi posle pogrešnog unos ili slučajnog pritiska na "delete" FOKUS ostao na tom textbox-u gde se neće dozvoliti prelaz na drugo polje dok prvo nije ok. Ako sam bio dovoljno jasan pomagaj.
[ Jpeca @ 15.12.2015. 08:32 ] @
Validaciju radiš u BeforeUpdate događaju umesto Exit
Cancel u tom slučaju je parametar Event procedure i služi da fokus ostane na aktivnoj kontroli

Code:

Private Sub txtVisina_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
   Cancel = False
   Validate Cancel
End Sub
Private Sub txtSirina_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
  Cancel = False
  Validate Cancel
End Sub

Private Sub Validate(ByRef Cancel As MSForms.ReturnBoolean)
' Procedura za validaciju vrednosti text boxa
 If TypeName(Me.ActiveControl) = "TextBox" Then
        With Me.ActiveControl
            If Not IsNumeric(.Value) Or (IsNumeric(.Value) And (.Value < 300 Or .Value > 6000)) Then
                MsgBox "Invalid input. Please enter a number b/w 300 and 6000.", vbCritical
                '.Value = vbNullString
                 Cancel = True   'prevent AfterUpdate and focus moving
                .SetFocus
             End If
        End With
 End If
End Sub