User form text box question

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
Is there a way to prevent someone from entering something into a text box on a user form that is not in a list? If I name the list can I enter that name some where in the properties to prevent it from being entered?

Thanks
 
Code:
Private Sub txtemplon_Change()
If Me.txtemplon.MatchFound = False Then
    MsgBox "Incorrect Item Number.", vbInformation, "Invalid Entry"
    Cancel = True
End If


End Sub
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
DK,
Also once the error comes up if I hit the enter button it puts it in the table anyways.
 
Upvote 0
It needs to be this - delete the txtemplon_Change macro.

Code:
Private Sub txtemplon_BeforeUpdate()
If Me.txtemplon.MatchFound = False Then
    MsgBox "Incorrect Item Number.", vbInformation, "Invalid Entry"
    Cancel = True
End If


End Sub
 
Upvote 0
Ok now I get a Compile error:
Procedure declaration does not match description of event or
procedure having the same name.
 
Upvote 0
In row source I have "employeenumber" that is the name of my list of numbers
 
Upvote 0
Sorry, that was my fault. Try this instead:

Code:
Private Sub txtemplon_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Me.txtemplon.MatchFound = False Then
    MsgBox "Incorrect Item Number.", vbInformation, "Invalid Entry"
    Cancel = True
End If
End Sub
 
Upvote 0
Well now when I press the enter button it gives me the error evin if the number is in the named range.

Thanks for your help on this
 
Upvote 0
Which error are you getting - is it your custom one or the "Invalid Property Value" one?

Have you made sure that the combobox MatchEntry is set to False?
 
Upvote 0
Custom - "Incorrect Item Number"

Match Enter set to : none

Match Required to : false
 
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,261
Members
449,307
Latest member
Andile

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top