|
-
Feb 13th, 2006, 09:22 AM
#1
Thread Starter
Lively Member
[RESOLVED] Form error in excel
Hi, I am a total newbie and I'm playing around with a little form where you enter a number then it finds and displays the appropriate info. It works ok apart from when you put the wrong number in, then it comes up with an error.
You'll have to have a look at it to understand what I mean.
-
Feb 13th, 2006, 09:39 AM
#2
Re: Form error in excel
 Originally Posted by thelocaluk
Hi, I am a total newbie and I'm playing around with a little form where you enter a number then it finds and displays the appropriate info. It works ok apart from when you put the wrong number in, then it comes up with an error.
You'll have to have a look at it to understand what I mean.
You code in the Find Button should test the rCell object like this
VB Code:
Set rCell = Cells.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
)
If rCell Is Nothing Then
bFound = False
MsgBox "Sorry, no matches", vbOKOnly
Else
bFound = True
ListBox1.AddItem rCell(1, 2).Cells
ListBox2.AddItem rCell(1, 3).Cells
End If
And why are you disabling the Error handler? It is always a good idea to have the Error Handler code in your procedure.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Feb 13th, 2006, 09:43 AM
#3
Re: Form error in excel
If you read the help file for the Find Method, it says "Returns Nothing if no match is found". You can use this to trap for those situations where the user enters an invalid Job Id.
To do this, you should change your IF statement from
VB Code:
If TextBox1 Like rCell Then
bFound = True
ListBox1.AddItem rCell(1, 2).Cells
ListBox2.AddItem rCell(1, 3).Cells
Else
bFound = False
MsgBox "Sorry, no matches", vbOKOnly
End If
to
VB Code:
If rCell Is Nothing Then
bFound = False
MsgBox "Sorry, no matches", vbOKOnly
Else
bFound = True
ListBox1.AddItem rCell(1, 2).Cells
ListBox2.AddItem rCell(1, 3).Cells
End If
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 13th, 2006, 10:19 AM
#4
Thread Starter
Lively Member
Re: Form error in excel
Thanks guys, it all makes perfect sense when you see it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|