VB Code Needed or Data Forms

Morrissey

Board Regular
Joined
Mar 8, 2002
Messages
85
Hi,

I've Made A Data Form Using Visual Basic And I've made An Input Where You Type Something And It Goes To The Requested Cell, However I Would Like It To Be Data That Is Valid So When Someone Types In The (For Example) Invoice Number 'S' A Pop Up Menu Will Say Please Enter A Number So I'd Like The Data Input Into The Box Only Data If It Helps Here IS The Code I've Started With:

Private Sub cmdEnterInvoiceData_Click()
Sheet1.Range("b11").Value = txtInvoiceNum

End Sub

Private Sub UserForm_Click()

End Sub
 
Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)

Hey Mudface This Line VBA Says It Has Errors On It Please Help


PS. Here Is All The Code I Have Input


Private Sub cmdEnterInvoiceData_Click()

Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
Exit Sub

WrongInput:
MsgBox "Please Enter A Valid Invoice Number"
txtInvoiceNum.Text = ""
txtInvoiceNum.SetFocus






End Sub

Private Sub txtInvoiceNum_Change()

End Sub

Private Sub UserForm_Click()

End Sub
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)

Hey Mudface This Line VBA Says It Has Errors On It Please Help


PS. Here Is All The Code I Have Input


Private Sub cmdEnterInvoiceData_Click()

Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
Exit Sub

WrongInput:
MsgBox "Please Enter A Valid Invoice Number"
txtInvoiceNum.Text = ""
txtInvoiceNum.SetFocus






End Sub

Private Sub txtInvoiceNum_Change()

End Sub

Private Sub UserForm_Click()

End Sub
 
Upvote 0
PS that debug error only comes up when I enter words however I want the error message to come up not the VBA debugger
 
Upvote 0
You've missed out the On Error ... line. The point of that is that it traps the error when you enter non-numeric data, and goes to the error handler called WrongInput. Select the code I posted, copy it ALL and paste it over your existing code.
 
Upvote 0
No, it's quite simple, copy the code below and paste it over your existing code, it works fine for me: -

Private Sub cmdEnterInvoiceData_Click()

On Error GoTo WrongInput
Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
Exit Sub

WrongInput:
MsgBox "Please enter a number"
txtInvoiceNum.Text = ""
txtInvoiceNum.SetFocus

End Sub
 
Upvote 0
Heh, you're right to doubt my talents :). You just missed a line out, that's all. Good luck with the rest, think you'll get a higher mark than Sami?
 
Upvote 0
Nah Sami stated the project three months before me and he did all the excel project book I did three chapters and started the project around late february using my own knowledge on ecel and this message board(it's in on friday) and I have done no implementation while Sami has doen about 20 pages
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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