ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check contents of text box (https://www.excelbanter.com/excel-programming/335734-check-contents-text-box.html)

vince c via OfficeKB.com

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

K Dales[_2_]

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


vince c via OfficeKB.com

Check contents of text box
 

Thanks. I'll give it a try.


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


All times are GMT +1. The time now is 05:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com