Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

VBA- Combo Box error message


  • Please log in to reply

#1
ChrisWright

ChrisWright

    Member

  • Member
  • PipPip
  • 34 posts
As odd as this may sound, I am looking for a way to change the message of the error given by VBA when a user enters an invalid choice in a combobox

I have used a combo box to give the user a number of options, added using the code shown below:

Private Sub UserForm_Activate()
Me.ComboBox1.AddItem "This"
Me.ComboBox1.AddItem "is"
Me.ComboBox1.AddItem "a"
Me.ComboBox1.AddItem "test!"
End Sub

Firstly, may I check that this is an acceptable method of adding ? For some reason I find this more logical than the 'For ComboBox1' method, although once my project is complete, I'll replace it with that :whistling:


I have set the 'Match Required' property of the combo box to 'True', so that when they enter something other than one of those choices, it will give an error message. The problem is that this message is simply titled "Microsoft Forms" with the message "Invalid property value".

The problem this poses me with is that my end user is... well.. 'less experienced' with ICT than some people, and may not understand why this error is occuring.

The main question here therefore is:
Can the title and/or the text in the error message be changed?




Notes:

I have currently tried the following code, but to no avail - any help or advice?
Private Sub ComboBox1_Error(ByVal Number As Integer, ByVal Description As MSForms.ReturnString, ByVal SCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, ByVal CancelDisplay As MSForms.ReturnBoolean)
Description = "The given value is incorrect, please type or pick another choice"
End Sub

Thanks in advance for reading, and thanks again for any help,
Chris W
  • 0

Advertisements


#2
paper

paper

    Member

  • Member
  • PipPip
  • 48 posts
Hi,

What you need is to allow the user only select an item from the list, right? Try this:

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
MsgBox "Please pick a choice by click the small arrow."
End Sub

Private Sub UserForm_Activate()
Me.ComboBox1.AddItem "This"
Me.ComboBox1.AddItem "is"
Me.ComboBox1.AddItem "a"
Me.ComboBox1.AddItem "test!"
Me.ComboBox1.ListIndex = 0
End Sub
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP