Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default exception to MsgBox

I am currently running this code to prevent users from leaving a
TextBox (txtPO) empty:

If Trim(Me.txtPO.Value) = "" Then
Me.txtPO.SetFocus
MsgBox "Please enter a Purchase Order Number."
Exit Sub
End If

I would like this to only apply if "A," "B," or "C" are entered into
cboDealer which is on the same user form. Otherwise I want the user to
be able to leave this TextBox Empty. Can anybody provide me the
appropriate code?

Thanks in advance for all of your help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default exception to MsgBox

Dim s as String
s = Trim(Me.cboDealer.Value)
if Len(s) = 1 and instr(1,"ABC",s,vbTextCompare)0 then
If Trim(Me.txtPO.Value) = "" Then
Me.txtPO.SetFocus
MsgBox "Please enter a Purchase Order Number."
Exit Sub
End If
End if

--
Regards,
Tom Ogilvy


"L Scholes" wrote in message
oups.com...
I am currently running this code to prevent users from leaving a
TextBox (txtPO) empty:

If Trim(Me.txtPO.Value) = "" Then
Me.txtPO.SetFocus
MsgBox "Please enter a Purchase Order Number."
Exit Sub
End If

I would like this to only apply if "A," "B," or "C" are entered into
cboDealer which is on the same user form. Otherwise I want the user to
be able to leave this TextBox Empty. Can anybody provide me the
appropriate code?

Thanks in advance for all of your help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default exception to MsgBox

In your code you have "ABC" on line 3. When I substitute for my list,
should I include the names without spaces or commas within one set of
quotes, or list each separately in their own quotes, separated by
commas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default exception to MsgBox

You asked a specific question and got a specific answer. It the choices are
not "A" "B" or "C", then the answer isn't appropriate

If the choices are actually three text strings of multiple characters than
checking for a len of 1 is inappropriate.

Dim s as String
s = "#" & Trim(Me.cboDealer.Value) & "#"
if instr(1,"#AAAAA#BBBBB#CCCCC#", _
s,vbTextCompare)0 then
If Trim(Me.txtPO.Value) = "" Then
Me.txtPO.SetFocus
MsgBox "Please enter a Purchase Order Number."
Exit Sub
End If
End if

Replace AAAAA, BBBBB, and CCCCC with your text strings.

--
Regards,
Tom Ogilvy




"L Scholes" wrote in message
ups.com...
In your code you have "ABC" on line 3. When I substitute for my list,
should I include the names without spaces or commas within one set of
quotes, or list each separately in their own quotes, separated by
commas?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default exception to MsgBox

Thank you sir, that works PERFECTLY!



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
sum of rows with exception of row x, y, z... lydia's Excel Discussion (Misc queries) 6 September 5th 09 03:54 PM
Exception list Gene Straub Excel Discussion (Misc queries) 2 January 28th 09 10:46 PM
Sum Based on Exception Cue New Users to Excel 9 May 22nd 08 12:44 AM
Sum Based on Exception Cue Excel Discussion (Misc queries) 7 May 21st 08 12:31 AM
Add an exception rule hotherps[_109_] Excel Programming 6 August 17th 04 05:51 PM


All times are GMT +1. The time now is 02: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"