Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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