Restrict a Text Box

  • Thread starter Thread starter Bob Vance
  • Start date Start date
Thanks Gina, Actually in size because someone could enter some data on the
next line and it wont be seen
Regards Bob
 
Bob,

Then what you would want is characters... You could put something like this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on the
next line and it wont be seen
Regards Bob
 
Thanks Gina, Just having trouble with the msgbox!
Regards Bob
Private Sub tbName_Exit(Cancel As Integer)

If Len([tbName]) > 80 Then
MsgBox "You have exceeded the 80 characters limit by "
&Len([tbName]) & " characters. It will not be seen in its entirety",
vbCritical , "Too Many Characters"
DoCmd.CancelEvent
End If


End Sub
Gina Whipp said:
Bob,

Then what you would want is characters... You could put something like
this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its
entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on the
next line and it wont be seen
Regards Bob
Gina Whipp said:
Bob,

In size or in characters? Not sure I understand...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Can you restrict a text box to only one line, my text box only shows one
line!
 
Bob,

You didn't say what problem but maybe word wrap?

The below should be all on one line...

MsgBox "You have exceeded the 80 characters limit by " & Len([tbName]) & "
characters. It will not be seen in its entirety",
vbCritical , "Too Many Characters"

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Just having trouble with the msgbox!
Regards Bob
Private Sub tbName_Exit(Cancel As Integer)

If Len([tbName]) > 80 Then
MsgBox "You have exceeded the 80 characters limit by "
&Len([tbName]) & " characters. It will not be seen in its entirety",
vbCritical , "Too Many Characters"
DoCmd.CancelEvent
End If


End Sub
Gina Whipp said:
Bob,

Then what you would want is characters... You could put something like
this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its
entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on the
next line and it wont be seen
Regards Bob
Gina Whipp said:
Bob,

In size or in characters? Not sure I understand...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Can you restrict a text box to only one line, my text box only shows one
line!
 
Thanks Gina, All Good
Private Sub tbName_Exit(Cancel As Integer)

If Len([tbName]) > 60 Then
MsgBox "You have exceeded the 60 characters limit "

DoCmd.CancelEvent
End If


End Sub
Bob Vance said:
Thanks Gina, Just having trouble with the msgbox!
Regards Bob
Private Sub tbName_Exit(Cancel As Integer)

If Len([tbName]) > 80 Then
MsgBox "You have exceeded the 80 characters limit by "
&Len([tbName]) & " characters. It will not be seen in its entirety",
vbCritical , "Too Many Characters"
DoCmd.CancelEvent
End If


End Sub
Gina Whipp said:
Bob,

Then what you would want is characters... You could put something like
this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its
entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on
the
next line and it wont be seen
Regards Bob
Gina Whipp said:
Bob,

In size or in characters? Not sure I understand...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Can you restrict a text box to only one line, my text box only shows one
line!
 
Glad to hear you got it working... Well, one of them!

You're welcome,
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, All Good
Private Sub tbName_Exit(Cancel As Integer)

If Len([tbName]) > 60 Then
MsgBox "You have exceeded the 60 characters limit "

DoCmd.CancelEvent
End If


End Sub
Bob Vance said:
Thanks Gina, Just having trouble with the msgbox!
Regards Bob
Private Sub tbName_Exit(Cancel As Integer)

If Len([tbName]) > 80 Then
MsgBox "You have exceeded the 80 characters limit by "
&Len([tbName]) & " characters. It will not be seen in its entirety",
vbCritical , "Too Many Characters"
DoCmd.CancelEvent
End If


End Sub
Gina Whipp said:
Bob,

Then what you would want is characters... You could put something like
this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its
entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on
the
next line and it wont be seen
Regards Bob
Gina Whipp said:
Bob,

In size or in characters? Not sure I understand...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Can you restrict a text box to only one line, my text box only shows one
line!
 
(e-mail address removed)
Gina Whipp said:
Bob,

Then what you would want is characters... You could put something like
this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its
entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on the
next line and it wont be seen
Regards Bob
Gina Whipp said:
Bob,

In size or in characters? Not sure I understand...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Can you restrict a text box to only one line, my text box only shows one
line!
 
James Hall said:
(e-mail address removed)
Gina Whipp said:
Bob,

Then what you would want is characters... You could put something like
this
in the On_Exit of the field...

'Watch out for word wrap
Private Sub txtYourTextBox_Exit(Cancel As Integer)
If Len([txtText]) > ??? Then
MsgBox "You have exceeded the ??? character limit by " &
Len([txtText]) - ??? & " characters. It will not be seen in its
entirety",
vbCritical, "Too Many Characters"
DoCmd.CancelEvent
End If
End Sub

OR

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)
'Posted by Dirk Goldgar, MS Access MVP
Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters will fit!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Thanks Gina, Actually in size because someone could enter some data on
the
next line and it wont be seen
Regards Bob
Gina Whipp said:
Bob,

In size or in characters? Not sure I understand...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Can you restrict a text box to only one line, my text box only shows one
line!
 
Back
Top