Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default limit textbox to blank or exactly 4 numberic digits

This works

Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtbxPhonePost.Value = "" Then
usfDemo.cmbxDOBMonth.SetFocus
Else
If IsNumeric(usfDemo.txtbxPhonePost.Text) = False Then
MsgBox "This box must be blank or contain exactly 4 numbers!",
vbOKOnly
Else
If Len(usfDemo.txtbxPhonePost.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4
numbers!", vbOKOnly
End If
End If
End If
End Sub

Is there a better way?
--
Thanks
Shawn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default limit textbox to blank or exactly 4 numberic digits

I added this below the message box:

MsgBox "This box must be blank or contain exactly 4 numbers!", vbOKOnly
If VBAOk Then
usfDemo.txtbxPhonePost.Text = ""
usfDemo.txtbxPhonePost.SetFocus
End If

However, the textbx doesn't clear or select?

--
Thanks
Shawn


"Shawn" wrote:

This works

Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtbxPhonePost.Value = "" Then
usfDemo.cmbxDOBMonth.SetFocus
Else
If IsNumeric(usfDemo.txtbxPhonePost.Text) = False Then
MsgBox "This box must be blank or contain exactly 4 numbers!",
vbOKOnly
Else
If Len(usfDemo.txtbxPhonePost.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4
numbers!", vbOKOnly
End If
End If
End If
End Sub

Is there a better way?
--
Thanks
Shawn

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default limit textbox to blank or exactly 4 numberic digits

maybe

If VBOk Then

Shawn wrote:

I added this below the message box:

MsgBox "This box must be blank or contain exactly 4 numbers!", vbOKOnly
If VBAOk Then
usfDemo.txtbxPhonePost.Text = ""
usfDemo.txtbxPhonePost.SetFocus
End If

However, the textbx doesn't clear or select?

--
Thanks
Shawn

"Shawn" wrote:

This works

Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtbxPhonePost.Value = "" Then
usfDemo.cmbxDOBMonth.SetFocus
Else
If IsNumeric(usfDemo.txtbxPhonePost.Text) = False Then
MsgBox "This box must be blank or contain exactly 4 numbers!",
vbOKOnly
Else
If Len(usfDemo.txtbxPhonePost.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4
numbers!", vbOKOnly
End If
End If
End If
End Sub

Is there a better way?
--
Thanks
Shawn


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default limit textbox to blank or exactly 4 numberic digits

But since you're not giving the user a choice, why bother checking the response?

msgbox "This box must be blank or contain exactly 4 numbers!", vbOKOnly
usfDemo.txtbxPhonePost.Text = ""
usfDemo.txtbxPhonePost.SetFocus



Shawn wrote:

I added this below the message box:

MsgBox "This box must be blank or contain exactly 4 numbers!", vbOKOnly
If VBAOk Then
usfDemo.txtbxPhonePost.Text = ""
usfDemo.txtbxPhonePost.SetFocus
End If

However, the textbx doesn't clear or select?

--
Thanks
Shawn

"Shawn" wrote:

This works

Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtbxPhonePost.Value = "" Then
usfDemo.cmbxDOBMonth.SetFocus
Else
If IsNumeric(usfDemo.txtbxPhonePost.Text) = False Then
MsgBox "This box must be blank or contain exactly 4 numbers!",
vbOKOnly
Else
If Len(usfDemo.txtbxPhonePost.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4
numbers!", vbOKOnly
End If
End If
End If
End Sub

Is there a better way?
--
Thanks
Shawn


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default limit textbox to blank or exactly 4 numberic digits

Hi,

Private Sub txtbxPhonePost_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < 48 Or KeyAscii 57 Then KeyAscii = 0 'Numeric keys only
End Sub

Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With txtbxPhonePost
If Len(.Text) 0 And Len(.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4 numbers!",
vbOKOnly
.Text = vbNullString'Clear the textbox
Cancel = True'Leave the focus on the textbox
End If
End With
End Sub

Is it ok?

Best regards from France,

Manu/

"Shawn" a écrit dans le message de news:
...
I added this below the message box:

MsgBox "This box must be blank or contain exactly 4 numbers!", vbOKOnly
If VBAOk Then
usfDemo.txtbxPhonePost.Text = ""
usfDemo.txtbxPhonePost.SetFocus
End If

However, the textbx doesn't clear or select?

--
Thanks
Shawn


"Shawn" wrote:

This works

Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtbxPhonePost.Value = "" Then
usfDemo.cmbxDOBMonth.SetFocus
Else
If IsNumeric(usfDemo.txtbxPhonePost.Text) = False Then
MsgBox "This box must be blank or contain exactly 4
numbers!",
vbOKOnly
Else
If Len(usfDemo.txtbxPhonePost.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4
numbers!", vbOKOnly
End If
End If
End If
End Sub

Is there a better way?
--
Thanks
Shawn





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Character limit in textbox Ashley Excel Worksheet Functions 1 September 10th 08 01:33 AM
Limit Number in cell to 5 Digits bdehning Excel Discussion (Misc queries) 4 December 19th 07 06:48 PM
Limit the amount of digits displayed in a field in Excel or Access Help with Excel Mail Merge Excel Discussion (Misc queries) 0 July 13th 06 05:09 PM
Limit Digits entered into a cell Mike Smith NC Excel Discussion (Misc queries) 1 July 7th 06 09:01 PM
in excel, how to limit digits of negative hexadecimal numbers? [email protected] Excel Discussion (Misc queries) 1 February 1st 06 11:36 PM


All times are GMT +1. The time now is 04:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"