Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default moving within forms

Hi,

I assume you have a button on your userform that closes it and does
something with the values. This code would be called by that button. It loops
through each textbox on the form and ensure the value is numeric and in
addition if textbox 3 is populated it checks if textbox1 is

Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
With cCont
If Not IsNumeric(.Value) And .Value < vbNullString Then
MsgBox cCont.Name & " value must be numeric"
.Value = vbNullString
End If
End With
End If

'Ensure box 1 is populated if box 3 has a value
If cCont.Name = "TextBox3" And cCont.Value < _
vbNullString And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
End If
Next cCont
End Sub

Mike

"TC" wrote:

Hi All.

I have a user form that acts as an inputbox, and there are 6 fields withing
the form.
None of the fields require any input - they can be left blank, but if a
value is input, it must be numeric. However, if there is a value entered into
say field3 then a value IS required for field1. So if field1 is blank, I give
an error message. What I need to do, once the error message is closed, is
place the cursor back into field1 so the user can type something in. I can't
find any code within VB that will do that!

thanks
TC



  #2   Report Post  
Posted to microsoft.public.excel.programming
TC TC is offline
external usenet poster
 
Posts: 32
Default moving within forms

Hi Mike, many thanks for the reply.

I think perhaps I over did it on the original question, but thanks for
taking the time out to give a full reply. I have all the validation, error
messages etc already in place and working.

field6 of the form is calculated based on the values of field1 and field3,
(if they have values). Therefore if the user has input a value for field3,
then there has to be be a value in field1. So far so good - it all works
without a problem. This is all done within the form, before closing it.

My real problem is that, having validated all the fields within the form, if
field3 is not null and not 0, and field1 is null or is 0, then I want to put
the cursor back into field1. That's where I need help. Unfortunately, and
assuming I'm reading your code correctly, your solution doesn't appear to do
that.

I'm sure it must be simple to move the cursor to a specific field in the
form, (it is in other programming languages I use), but I have a lack of
experience in VB.

TC




"Mike H" wrote:

Hi,

I assume you have a button on your userform that closes it and does
something with the values. This code would be called by that button. It loops
through each textbox on the form and ensure the value is numeric and in
addition if textbox 3 is populated it checks if textbox1 is

Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
With cCont
If Not IsNumeric(.Value) And .Value < vbNullString Then
MsgBox cCont.Name & " value must be numeric"
.Value = vbNullString
End If
End With
End If

'Ensure box 1 is populated if box 3 has a value
If cCont.Name = "TextBox3" And cCont.Value < _
vbNullString And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
End If
Next cCont
End Sub

Mike

"TC" wrote:

Hi All.

I have a user form that acts as an inputbox, and there are 6 fields withing
the form.
None of the fields require any input - they can be left blank, but if a
value is input, it must be numeric. However, if there is a value entered into
say field3 then a value IS required for field1. So if field1 is blank, I give
an error message. What I need to do, once the error message is closed, is
place the cursor back into field1 so the user can type something in. I can't
find any code within VB that will do that!

thanks
TC



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default moving within forms

Hi,

This checks textbox 3 for a number and if true checks textbox1 is populated
and if it isn't gives the focus to textbox1

Private Sub CommandButton1_Click()
If TextBox3.Value < vbNullString And _
TextBox3.Value < 0 _
And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
TextBox1.SetFocus
Else

'do other things

End If

End Sub


Mike

"TC" wrote:

Hi Mike, many thanks for the reply.

I think perhaps I over did it on the original question, but thanks for
taking the time out to give a full reply. I have all the validation, error
messages etc already in place and working.

field6 of the form is calculated based on the values of field1 and field3,
(if they have values). Therefore if the user has input a value for field3,
then there has to be be a value in field1. So far so good - it all works
without a problem. This is all done within the form, before closing it.

My real problem is that, having validated all the fields within the form, if
field3 is not null and not 0, and field1 is null or is 0, then I want to put
the cursor back into field1. That's where I need help. Unfortunately, and
assuming I'm reading your code correctly, your solution doesn't appear to do
that.

I'm sure it must be simple to move the cursor to a specific field in the
form, (it is in other programming languages I use), but I have a lack of
experience in VB.

TC




"Mike H" wrote:

Hi,

I assume you have a button on your userform that closes it and does
something with the values. This code would be called by that button. It loops
through each textbox on the form and ensure the value is numeric and in
addition if textbox 3 is populated it checks if textbox1 is

Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
With cCont
If Not IsNumeric(.Value) And .Value < vbNullString Then
MsgBox cCont.Name & " value must be numeric"
.Value = vbNullString
End If
End With
End If

'Ensure box 1 is populated if box 3 has a value
If cCont.Name = "TextBox3" And cCont.Value < _
vbNullString And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
End If
Next cCont
End Sub

Mike

"TC" wrote:

Hi All.

I have a user form that acts as an inputbox, and there are 6 fields withing
the form.
None of the fields require any input - they can be left blank, but if a
value is input, it must be numeric. However, if there is a value entered into
say field3 then a value IS required for field1. So if field1 is blank, I give
an error message. What I need to do, once the error message is closed, is
place the cursor back into field1 so the user can type something in. I can't
find any code within VB that will do that!

thanks
TC



  #4   Report Post  
Posted to microsoft.public.excel.programming
TC TC is offline
external usenet poster
 
Posts: 32
Default moving within forms

Prefect ! Thank you so much. Have a great New Year.

"Mike H" wrote:

Hi,

This checks textbox 3 for a number and if true checks textbox1 is populated
and if it isn't gives the focus to textbox1

Private Sub CommandButton1_Click()
If TextBox3.Value < vbNullString And _
TextBox3.Value < 0 _
And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
TextBox1.SetFocus
Else

'do other things

End If

End Sub


Mike

"TC" wrote:

Hi Mike, many thanks for the reply.

I think perhaps I over did it on the original question, but thanks for
taking the time out to give a full reply. I have all the validation, error
messages etc already in place and working.

field6 of the form is calculated based on the values of field1 and field3,
(if they have values). Therefore if the user has input a value for field3,
then there has to be be a value in field1. So far so good - it all works
without a problem. This is all done within the form, before closing it.

My real problem is that, having validated all the fields within the form, if
field3 is not null and not 0, and field1 is null or is 0, then I want to put
the cursor back into field1. That's where I need help. Unfortunately, and
assuming I'm reading your code correctly, your solution doesn't appear to do
that.

I'm sure it must be simple to move the cursor to a specific field in the
form, (it is in other programming languages I use), but I have a lack of
experience in VB.

TC




"Mike H" wrote:

Hi,

I assume you have a button on your userform that closes it and does
something with the values. This code would be called by that button. It loops
through each textbox on the form and ensure the value is numeric and in
addition if textbox 3 is populated it checks if textbox1 is

Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
With cCont
If Not IsNumeric(.Value) And .Value < vbNullString Then
MsgBox cCont.Name & " value must be numeric"
.Value = vbNullString
End If
End With
End If

'Ensure box 1 is populated if box 3 has a value
If cCont.Name = "TextBox3" And cCont.Value < _
vbNullString And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
End If
Next cCont
End Sub

Mike

"TC" wrote:

Hi All.

I have a user form that acts as an inputbox, and there are 6 fields withing
the form.
None of the fields require any input - they can be left blank, but if a
value is input, it must be numeric. However, if there is a value entered into
say field3 then a value IS required for field1. So if field1 is blank, I give
an error message. What I need to do, once the error message is closed, is
place the cursor back into field1 so the user can type something in. I can't
find any code within VB that will do that!

thanks
TC



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default moving within forms

Your welcome


"TC" wrote:

Prefect ! Thank you so much. Have a great New Year.

"Mike H" wrote:

Hi,

This checks textbox 3 for a number and if true checks textbox1 is populated
and if it isn't gives the focus to textbox1

Private Sub CommandButton1_Click()
If TextBox3.Value < vbNullString And _
TextBox3.Value < 0 _
And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
TextBox1.SetFocus
Else

'do other things

End If

End Sub


Mike

"TC" wrote:

Hi Mike, many thanks for the reply.

I think perhaps I over did it on the original question, but thanks for
taking the time out to give a full reply. I have all the validation, error
messages etc already in place and working.

field6 of the form is calculated based on the values of field1 and field3,
(if they have values). Therefore if the user has input a value for field3,
then there has to be be a value in field1. So far so good - it all works
without a problem. This is all done within the form, before closing it.

My real problem is that, having validated all the fields within the form, if
field3 is not null and not 0, and field1 is null or is 0, then I want to put
the cursor back into field1. That's where I need help. Unfortunately, and
assuming I'm reading your code correctly, your solution doesn't appear to do
that.

I'm sure it must be simple to move the cursor to a specific field in the
form, (it is in other programming languages I use), but I have a lack of
experience in VB.

TC




"Mike H" wrote:

Hi,

I assume you have a button on your userform that closes it and does
something with the values. This code would be called by that button. It loops
through each textbox on the form and ensure the value is numeric and in
addition if textbox 3 is populated it checks if textbox1 is

Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
With cCont
If Not IsNumeric(.Value) And .Value < vbNullString Then
MsgBox cCont.Name & " value must be numeric"
.Value = vbNullString
End If
End With
End If

'Ensure box 1 is populated if box 3 has a value
If cCont.Name = "TextBox3" And cCont.Value < _
vbNullString And TextBox1.Value = vbNullString Then
MsgBox "Text Box 1 cannot be empty with a value in textbox 3"
End If
Next cCont
End Sub

Mike

"TC" wrote:

Hi All.

I have a user form that acts as an inputbox, and there are 6 fields withing
the form.
None of the fields require any input - they can be left blank, but if a
value is input, it must be numeric. However, if there is a value entered into
say field3 then a value IS required for field1. So if field1 is blank, I give
an error message. What I need to do, once the error message is closed, is
place the cursor back into field1 so the user can type something in. I can't
find any code within VB that will do that!

thanks
TC



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
Moving text around cells without moving boarder lines Dale Excel Discussion (Misc queries) 1 December 15th 09 06:14 PM
Arrow Keys Moving Window Frame instead of Moving Between Cells nemmex Excel Discussion (Misc queries) 2 April 9th 07 09:08 AM
Excel forms - authorise / deny forms Ian Manning Excel Programming 1 May 8th 06 05:03 PM
RefEdits and normal forms / forms in a DLL David Welch Excel Programming 0 December 1st 04 03:49 PM
Calling Forms from Forms - Exit problems Stuart[_5_] Excel Programming 3 May 25th 04 06:50 AM


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