Hi All,
I wish to make entries into a database by using a Userform. The first textbox is named 'txtInv' and this is for entering the Invoice No. The format of the invoice no. is alphanumeric - two alphabets followed by either 3 or 4 numbers, e.g. 'PQ###' or 'PQ####'.
I also wish to make it possible for users to enter the preceding two alphabets either in small letters.e.g. 'pq' or in capital letters, e.g. 'PQ'. Anything else should bring up an error message box.
I came up with the following code which I gleaned from a previous code, but I am not sure I got it right as it is coming up with error message:
I should be grateful for a correction to the code to make it work for me. I must confess that I am very new to VBA. Therefore, if the code does not make much sense and an alternative would be appropriate, I would be glad for help with it.
Thanks for any anticipated help.
Kenny
I wish to make entries into a database by using a Userform. The first textbox is named 'txtInv' and this is for entering the Invoice No. The format of the invoice no. is alphanumeric - two alphabets followed by either 3 or 4 numbers, e.g. 'PQ###' or 'PQ####'.
I also wish to make it possible for users to enter the preceding two alphabets either in small letters.e.g. 'pq' or in capital letters, e.g. 'PQ'. Anything else should bring up an error message box.
I came up with the following code which I gleaned from a previous code, but I am not sure I got it right as it is coming up with error message:
Code:
[FONT=Arial]Private Sub txtInv_Exit(ByVal Cancel As MSForms.ReturnBoolean)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT]
[FONT=Arial]If txtInv.Value = vbNullString Then Exit Sub<o:p></o:p>[/FONT]
[FONT=Arial]If (Not UCase(Me.txtInv.Value)Like "PQ###")And<o:p></o:p>[/FONT]
[FONT=Arial]If (Not UCase(Me.txtInv.Value) Like "PQ####") Then<o:p></o:p>[/FONT]
[FONT=Arial]MsgBox "Non Valid Invoice Number"<o:p></o:p>[/FONT]
[FONT=Arial]Cancel = True<o:p></o:p>[/FONT]
[FONT=Arial]End If<o:p></o:p>[/FONT]
[FONT=Arial]End Sub<o:p></o:p>[/FONT]
I should be grateful for a correction to the code to make it work for me. I must confess that I am very new to VBA. Therefore, if the code does not make much sense and an alternative would be appropriate, I would be glad for help with it.
Thanks for any anticipated help.
Kenny
Last edited: