• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Userform has to allow input from only one of the two inputboxes

swetha690

New Member
Hi all,


I am writing a simple user form to get data entered directly into cells in a spreadsheet. I have a combo box(ListBox1) and a TextBox(TextBox1) in the user form. I would like to erase the previous values entered each time the user form is loaded. I have included statements for this in the Initialize sub routine but for some reason this does not seem to work.


Also, I would like to allow value to be entered from only one of the two possible ways to enter data i.e listbox or the textbox. What happens with my code is that If there are values in both the boxes, the value from the listbox is taken and entered. I am not sure how to proceed with it. The code that I have used is as follows:

[pre]
Code:
Private Sub OKBtn_Click()
If Len(Me.ListBox1.Value) + Len(Me.TextBox1.Value) = 0 Then
MsgBox "Please enter an option..", vbExclamation, "Data"
Me.TextBox1.SetFocus

ElseIf Len(Me.ListBox1.Value) <> 0 Then
ActiveCell.Value = ListBox1.Value
Me.Hide

ElseIf Len(TextBox1.Value) <> 0 Then

ActiveCell.Value = TextBox1.Value
Me.Hide

End If

End Sub

Private Sub Cancel_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
ListBox1.Value = ""
TextBox1.Value = ""
End Sub
[/pre]

It would be great if anybody can help me out on this.


Thank You in advance.
 
Back
Top