PDA

View Full Version : [SOLVED:] UF Run Macro if LEN equals a number



Emoncada
08-04-2014, 02:44 PM
What I would like the form to do is


Private Sub TxtSerial_Change()
if Me.Optionbutton1. value = true Then

'run a macro when Len(TxtSerial.value)= 8

Else

if Me.Optionbutton2.value = true Then

'run a macro when Len(TxtSerial.value)= 10


Can anyone assist on how I can accomplish this?

Aussiebear
08-04-2014, 03:03 PM
You could try something like this maybe.

Private Sub TxtSerial_Change()
If Me.Optionbutton1.Value = True Then
If Len(TxtSerial.Value) = 8 Then
Call 'Macro Name
Else
MsgBox "Please check your entry"
End if
End if
Else
If Me.OptionButton2.Value = True then
If Len(TxtSerial.Value) = 10 Then
Call 'Macro Name
Else
MsgBox "Please check your entry"
End If
End if
End Sub

Emoncada
08-04-2014, 03:39 PM
I was so close, that worked. Thanks

Bob Phillips
08-04-2014, 04:11 PM
You could reduce that a bit


Private Sub TxtSerial_Change()
With Me

If (.Optionbutton1.Value And Len(.TxtSerial.Value) = 8) Or _
(.OptionButton2.Value And Len(.TxtSerial.Value) = 10) Then

Call Macro_Name
Else
MsgBox "Please check your entry"
End If
End With
End Sub