[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/14/2005 at 07:37PM PDT, ID: 21562051
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Userform - validate controls data when a listbox on the form

Asked by sebastienm in Microsoft Excel Spreadsheet Software

Tags: excel, userform, listbox

Hi guys,
I have an issue with userform and validation of data (not on an excel sheet here)
On the userform, Userform1, I have:
- a listbox called lbx
- a textbox called txt
- a command button called cmd
I fill the listbox during _Initialize and check the data in txt_BeforeUpdate(Cancel) and cancels the update if not valid data.
Now, if the data is not valid, i warn the user with a message and i'd like to give him a chance to change the enter data.
When running, if you enter data and click another item in the listbox, the message is displayed, but the listbox updates to the new selection preventing the user to re-entrer the data for his previous selection. I have posted my code below.

I have tried the txt_Exit event too, but to no avail.
Any idea would be greatly appreciated.

Thanks,
Sebastien

Here is the code:
'-------------------------------------------------------------------------------
Option Explicit

Private StoredValue() As Double

Private CodeMode As Boolean 'to cancel events when they are
                            ' triggered from my code and not
                            ' from the user

'Filling the listbox first
Private Sub UserForm_Initialize()
   Dim i As Long, ttl As Long
   
   CodeMode = True  'prevent events
   
   With lbx
      .AddItem "aaa"
      .AddItem "bbb"
   End With
   
   ttl = lbx.ListCount
   ReDim StoredValue(0 To ttl - 1)
   For i = 0 To ttl - 1: StoredValue(i) = i: Next
   
   CodeMode = False
End Sub

'When listbox is clicked, show the corresponding
' value in the textbox txt
Private Sub lbx_Click()
   'Cancel event if CodeMode
   If CodeMode Then Exit Sub
   
   txt = StoredValue(lbx.ListIndex)
   
End Sub

'Now the user can edit the textbox
'Validation: check data when the usere leaves the textbox
'       it has to be a number else prevent the update
Private Sub txt_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
   Dim d As Double
   
   CodeMode = True 'cancel events
   
   'Validation
   On Error Resume Next
   d = CDbl(txt)
   If Err <> 0 Then
      MsgBox "you must enter a number"
      Cancel = True 'Cancel the update of the textbox
   Else
      StoredValue(lbx.ListIndex) = CDbl(txt)
   End If
   
   CodeMode = False
End Sub
'----------------------------------------------------------------
[+][-]09/14/05 08:01 PM, ID: 14886527

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: excel, userform, listbox
Sign Up Now!
Solution Provided By: tony_813
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09/14/05 08:17 PM, ID: 14886575

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/05 10:31 PM, ID: 14886924

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/05 10:37 PM, ID: 14886937

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/05 05:46 AM, ID: 14888700

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/05 06:50 AM, ID: 14889217

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/14/05 04:17 PM, ID: 15089605

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/05 12:46 PM, ID: 15242529

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91