Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Check contents of text box


A data entry form includes a simple check to determine if a entry was made in
the text box txtFILE. If nothing was entered, then the cursor is returned to
the text box and a message displayed. The code appears below.

If Trim(Me.txtFILE.Value) = "" Then
Me.txtFILE.SetFocus
MsgBox "Please enter a FILE"
Exit Sub
End If

I'd like to also check that an entry to text box txtFILE is exactly 7
characters long and the first three characters are letters (e.g. ABC, FGH, et.
) and the last four characters are numbers (e.g. 1234, 4562, etc.)

Alternatively, I'd like to check that txtFILE is exactly 9 characters long
(including a decimal point) and the first three characters are letters (e.g.
ABC, FGH, et.) and the last six characters are numbers with a single decimal
(e.g. 1234.1, 4562.9, etc.)


--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Check contents of text box

CheckStr = Me.txtFILE.Value
If ((CheckStr = "") _
Or (CheckStr like "[A-Z][A-Z][A-Z]####") _
Or (CheckStr like "[A-Z][A-Z][A-Z]####.#")) _
Then
Me.txtFILE.SetFocus
MsgBox "Please enter a FILE"
Exit Sub
End If

Note: you may want to ensure it is uppercase before the checks:
Me.txtFILE.Value = UCase(Me.txtFILE.Value)
--
- K Dales


"vince c via OfficeKB.com" wrote:


A data entry form includes a simple check to determine if a entry was made in
the text box txtFILE. If nothing was entered, then the cursor is returned to
the text box and a message displayed. The code appears below.

If Trim(Me.txtFILE.Value) = "" Then
Me.txtFILE.SetFocus
MsgBox "Please enter a FILE"
Exit Sub
End If

I'd like to also check that an entry to text box txtFILE is exactly 7
characters long and the first three characters are letters (e.g. ABC, FGH, et.
) and the last four characters are numbers (e.g. 1234, 4562, etc.)

Alternatively, I'd like to check that txtFILE is exactly 9 characters long
(including a decimal point) and the first three characters are letters (e.g.
ABC, FGH, et.) and the last six characters are numbers with a single decimal
(e.g. 1234.1, 4562.9, etc.)


--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Check contents of text box


Thanks. I'll give it a try.


--
Message posted via http://www.officekb.com
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
vba to check cell contents Steve Excel Discussion (Misc queries) 2 July 29th 09 04:58 PM
Using contents of a check box for an in statement Erin Excel Discussion (Misc queries) 3 June 21st 07 05:23 PM
Fussy check of cell contents access_mk Excel Discussion (Misc queries) 1 April 19th 06 01:28 PM
IF statement to check cell contents Lance Gray Excel Worksheet Functions 1 May 29th 05 10:53 PM
Range Contents Check James Montgomery Excel Programming 2 October 24th 04 03:31 PM


All times are GMT +1. The time now is 06:35 AM.

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

About Us

"It's about Microsoft Excel"