Memo field size vba help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I need to limit a few memo txtboxes to 300 characters. I have searched
the net and could only find this code but I want to have a msg if the limit
was exceeded. How is this done? Thanks!

Private Sub MyTextBox_Change()
If Len(Me.MyTextBox.Text & "") > 300
Me.MyTextBox = Left(Me.MyTextBox.Text,300)
Me.MyTextBox.SelStart = 300
End If
End Sub
 
Chad said:
Hello, I need to limit a few memo txtboxes to 300 characters. I have
searched
the net and could only find this code but I want to have a msg if the
limit
was exceeded. How is this done? Thanks!

Private Sub MyTextBox_Change()
If Len(Me.MyTextBox.Text & "") > 300
Me.MyTextBox = Left(Me.MyTextBox.Text,300)
Me.MyTextBox.SelStart = 300
End If
End Sub

Something like:

Private Sub MyTextBox_Change()
If Len(Me.MyTextBox.Text & "") > 300 Then
MsgBox "You cannot enter more than 300 characters in this
field.",vbExclamation,"Field Length Exceeded"
Me.MyTextBox = Left(Me.MyTextBox.Text,300)
Me.MyTextBox.SelStart = 300
End If
End Sub

Ed Metcalfe.
 
Back
Top