A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Number only in a textbox



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 15th 06, 09:01 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 1
Default Number only in a textbox

Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.

  #2  
Old September 15th 06, 09:25 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Number only in a textbox

Well, for one thing, you need 5, not 4, and another close parenthesis:

IsNumeric(Item.UserProperties("Year")) = False

That kind of complex If block is too hard to debug for my taste. The way you have it written, all three tests are conducted for every value. Instead, you should only need to conduct all three for entries with 1 to 4 characters. I'd organize it like this:

strYear = Item.UserProperties("Year")
blnIsBad = False
If Len(strYear) 4 Then
blnIsBad = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsBad = True
End If
End If
If blnIsBad = True Then
msgbox "Invalid. Must be 4-digits and no letters"
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.

  #3  
Old September 15th 06, 10:18 PM posted to microsoft.public.outlook.program_vba
nabeyaki-udon
external usenet poster
 
Posts: 5
Default Number only in a textbox

Yes, this looks easier. I'll give this a try.

Sue Mosher [MVP-Outlook] wrote:
Well, for one thing, you need 5, not 4, and another close parenthesis:

IsNumeric(Item.UserProperties("Year")) = False

That kind of complex If block is too hard to debug for my taste. The way you have it written, all three tests are conducted for every value. Instead, you should only need to conduct all three for entries with 1 to 4 characters. I'd organize it like this:

strYear = Item.UserProperties("Year")
blnIsBad = False
If Len(strYear) 4 Then
blnIsBad = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsBad = True
End If
End If
If blnIsBad = True Then
msgbox "Invalid. Must be 4-digits and no letters"
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.


  #4  
Old September 18th 06, 05:33 PM posted to microsoft.public.outlook.program_vba
nabeyaki-udon
external usenet poster
 
Posts: 5
Default Number only in a textbox

Okay. So I did some tweaking to what you gave me and it seems to be
work correctly... At least I think it does.

strYear = Item.UserProperties("Year").Value
blnIsYear = False

If Len(strYear) 0 and Len(StrYear) 4 Then
blnIsYear = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsYear = True
End If
End If

If blnIsYear = True Then
msbox("Year must be 4-digits and no letters")
End If

Thanks for your input, Sue.

Sue Mosher [MVP-Outlook] wrote:
Well, for one thing, you need 5, not 4, and another close parenthesis:

IsNumeric(Item.UserProperties("Year")) = False

That kind of complex If block is too hard to debug for my taste. The way you have it written, all three tests are conducted for every value. Instead, you should only need to conduct all three for entries with 1 to 4 characters. I'd organize it like this:

strYear = Item.UserProperties("Year")
blnIsBad = False
If Len(strYear) 4 Then
blnIsBad = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsBad = True
End If
End If
If blnIsBad = True Then
msgbox "Invalid. Must be 4-digits and no letters"
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.


  #5  
Old September 18th 06, 06:05 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Number only in a textbox

You might want to rename your Boolean flag to something like blnIsNotAYear to make the code more readable.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"nabeyaki-udon" wrote in message oups.com...
Okay. So I did some tweaking to what you gave me and it seems to be
work correctly... At least I think it does.

strYear = Item.UserProperties("Year").Value
blnIsYear = False

If Len(strYear) 0 and Len(StrYear) 4 Then
blnIsYear = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsYear = True
End If
End If

If blnIsYear = True Then
msbox("Year must be 4-digits and no letters")
End If

Thanks for your input, Sue.

Sue Mosher [MVP-Outlook] wrote:
Well, for one thing, you need 5, not 4, and another close parenthesis:

IsNumeric(Item.UserProperties("Year")) = False

That kind of complex If block is too hard to debug for my taste. The way you have it written, all three tests are conducted for every value. Instead, you should only need to conduct all three for entries with 1 to 4 characters. I'd organize it like this:

strYear = Item.UserProperties("Year")
blnIsBad = False
If Len(strYear) 4 Then
blnIsBad = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsBad = True
End If
End If
If blnIsBad = True Then
msgbox "Invalid. Must be 4-digits and no letters"
End If



wrote in message oups.com...
Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.


  #6  
Old September 18th 06, 06:30 PM posted to microsoft.public.outlook.program_vba
nabeyaki-udon
external usenet poster
 
Posts: 5
Default Number only in a textbox

Yes. That will make it easier for someone else.

Thanks again!

Sue Mosher [MVP-Outlook] wrote:
You might want to rename your Boolean flag to something like blnIsNotAYear to make the code more readable.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"nabeyaki-udon" wrote in message oups.com...
Okay. So I did some tweaking to what you gave me and it seems to be
work correctly... At least I think it does.

strYear = Item.UserProperties("Year").Value
blnIsYear = False

If Len(strYear) 0 and Len(StrYear) 4 Then
blnIsYear = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsYear = True
End If
End If

If blnIsYear = True Then
msbox("Year must be 4-digits and no letters")
End If

Thanks for your input, Sue.

Sue Mosher [MVP-Outlook] wrote:
Well, for one thing, you need 5, not 4, and another close parenthesis:

IsNumeric(Item.UserProperties("Year")) = False

That kind of complex If block is too hard to debug for my taste. The way you have it written, all three tests are conducted for every value. Instead, you should only need to conduct all three for entries with 1 to 4 characters. I'd organize it like this:

strYear = Item.UserProperties("Year")
blnIsBad = False
If Len(strYear) 4 Then
blnIsBad = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsBad = True
End If
End If
If blnIsBad = True Then
msgbox "Invalid. Must be 4-digits and no letters"
End If



wrote in message oups.com...
Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.



  #7  
Old September 18th 06, 06:07 PM posted to microsoft.public.outlook.program_vba
nabeyaki-udon
external usenet poster
 
Posts: 5
Default Number only in a textbox

Also, thanks helping me out with the logic. I didn't know you could do
nested if's in VBScript.

Sue Mosher [MVP-Outlook] wrote:
Well, for one thing, you need 5, not 4, and another close parenthesis:

IsNumeric(Item.UserProperties("Year")) = False

That kind of complex If block is too hard to debug for my taste. The way you have it written, all three tests are conducted for every value. Instead, you should only need to conduct all three for entries with 1 to 4 characters. I'd organize it like this:

strYear = Item.UserProperties("Year")
blnIsBad = False
If Len(strYear) 4 Then
blnIsBad = True
ElseIf Len(strYear) 0 Then
If Not IsNumeric(strYear) Then
blnIsBad = True
End If
End If
If blnIsBad = True Then
msgbox "Invalid. Must be 4-digits and no letters"
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
Has anyone done this?

I'm trying to make a textbox called, Year, and it should be the
following:
- Allow Null Values
- Must be 4-digits (numbers), no less or not greater.


I tried using this logic:
If Len(Item.UserProperties("Year").Value) 0 And
Len(Item.UserProperties("Year").Value) 4 And
IsNumeric(Item.UserProperties("Year") = False Then
msgbox("Invalid. Must be 4-digits and no letters")
End If


For some reason it doesn't go through the IsNumeric() part. So I tried

searching for a Key event method and it's seems like Outlook doesn't
have such a thing... or I could be wrong.


Also, I've tried using a Number field, but it keeps default the value
with 0 which I can't get rid of.


Any suggestions? Any thoughts would be much appreciated.


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating one textbox using another? Zer0 Outlook - General Queries 3 August 4th 06 07:57 PM
Enable Disable the To textbox [email protected] Outlook - Using Forms 1 May 23rd 06 09:54 PM
cant overtype on custom form textbox Sydney Outlook - Using Forms 18 April 7th 06 05:58 AM
Textbox in forms Lorena Outlook - Using Forms 1 April 7th 06 12:19 AM
Textbox - Calculate Inititial Value Sydney Outlook - Using Forms 2 March 28th 06 01:26 AM


All times are GMT +1. The time now is 08:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.