Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default VBA code for empty txt field

Hi all,
New to VBA, so forgive my ignorace.

I have the following:
user form
combo box: cmbYESNO
text field: txtIFNOWHY

What I'm trying to accomplish is making sure that the user doens't forget to
populate the cmbYESNO and depending on the value of this combo box, whether
or not txtIFNOWHY needs to be filled out. I have the following code which i
picked up from a differnt thread on this site, which works for ensuring that
the cmbYESNO is filled out, but i can't seem to get the second part of the
code. Any help is appreciated. Thanks
Here is my code:

If Trim(Me.cmbYESNO.Value) = "" Then
Me.cmbYESNO.SetFocus
MsgBox "PLEASE INDICATE IF REVERSAL WAS SAVED"
If Trim(Me.cmbYESNO.Value) = "NO" Then
Me.txtIFNOWHY.SetFocus
If Trim(txtIFNOWHY.Value) = "" Then
MsgBox "PLEASE ENTER REASON REVERSAL WAS NOT SAVED"
Exit Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/201001/1

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default VBA code for empty txt field

It appears that you are missing some End If and Else statements. You
need something like

If Trim(Me.cmbYESNO.Value) = "" Then
Me.cmbYESNO.SetFocus
MsgBox "PLEASE INDICATE IF REVERSAL WAS SAVED"
Else
If Trim(Me.cmbYESNO.Value) = "NO" Then
Me.txtIFNOWHY.SetFocus
Else
If Trim(txtIFNOWHY.Value) = "" Then
MsgBox "PLEASE ENTER REASON REVERSAL WAS NOT SAVED"
Exit Sub
End If
End If
End If

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Fri, 22 Jan 2010 21:58:22 GMT, "AccessUser777 via OfficeKB.com"
<u44103@uwe wrote:

Hi all,
New to VBA, so forgive my ignorace.

I have the following:
user form
combo box: cmbYESNO
text field: txtIFNOWHY

What I'm trying to accomplish is making sure that the user doens't forget to
populate the cmbYESNO and depending on the value of this combo box, whether
or not txtIFNOWHY needs to be filled out. I have the following code which i
picked up from a differnt thread on this site, which works for ensuring that
the cmbYESNO is filled out, but i can't seem to get the second part of the
code. Any help is appreciated. Thanks
Here is my code:

If Trim(Me.cmbYESNO.Value) = "" Then
Me.cmbYESNO.SetFocus
MsgBox "PLEASE INDICATE IF REVERSAL WAS SAVED"
If Trim(Me.cmbYESNO.Value) = "NO" Then
Me.txtIFNOWHY.SetFocus
If Trim(txtIFNOWHY.Value) = "" Then
MsgBox "PLEASE ENTER REASON REVERSAL WAS NOT SAVED"
Exit Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA code for empty txt field

Nothing to do with your code...

But you may want to consider using a checkbox--checked means yes, unchecked
means no. As a user, I would find that more consistent with other forms I have
to fill out.

And it may make the code slightly easier, too.

If Me.chkbxYESNO.Value = true Then
'ok???
else
if trim(txtifnowhy.value) = "" then
me.txtifnowhy.setfocus
MsgBox "PLEASE ENTER REASON REVERSAL WAS NOT SAVED"
Exit Sub
end if
end if

===
You could use a pair of optionbuttons if you wanted, too.



"AccessUser777 via OfficeKB.com" wrote:

Hi all,
New to VBA, so forgive my ignorace.

I have the following:
user form
combo box: cmbYESNO
text field: txtIFNOWHY

What I'm trying to accomplish is making sure that the user doens't forget to
populate the cmbYESNO and depending on the value of this combo box, whether
or not txtIFNOWHY needs to be filled out. I have the following code which i
picked up from a differnt thread on this site, which works for ensuring that
the cmbYESNO is filled out, but i can't seem to get the second part of the
code. Any help is appreciated. Thanks
Here is my code:

If Trim(Me.cmbYESNO.Value) = "" Then
Me.cmbYESNO.SetFocus
MsgBox "PLEASE INDICATE IF REVERSAL WAS SAVED"
If Trim(Me.cmbYESNO.Value) = "NO" Then
Me.txtIFNOWHY.SetFocus
If Trim(txtIFNOWHY.Value) = "" Then
MsgBox "PLEASE ENTER REASON REVERSAL WAS NOT SAVED"
Exit Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/201001/1


--

Dave Peterson
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
Ignoring empty field in sum Redsphynx Excel Worksheet Functions 5 December 2nd 08 08:50 AM
empty values for a specific field avi Excel Discussion (Misc queries) 0 December 10th 07 10:09 AM
Sum only if corresponding field is not empty [email protected] Charts and Charting in Excel 2 April 11th 06 02:01 PM
Go to Next Empty Field cassy01 Excel Discussion (Misc queries) 1 February 20th 06 10:18 AM
Hide empty field error J Excel Worksheet Functions 3 June 28th 05 05:10 AM


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