Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 29th, 2005, 07:51 PM
Don D. Heeter Don D. Heeter is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 Don D. Heeter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 2 sec
Reputation Power: 0
Send a message via AIM to Don D. Heeter
Loop Question?

I am trying to make this code work and I need some help please.
Here is my problem - I can not get the err Trap loop to work?
If I enter a name in the Input box that is not in the database it will loop and ask me again,
But If I enter another wrong name it will error out.
I am trying to get it to keep looking (Looping) untill it finds a name in the data base or I tell it to quit looking.
I don't have the i = i and Do and i = i + 1 and loop in the correct place and I am not that good at VBA and I am trying to learn it.
Thank you for your help.

Code:
  Sub LineSearch()
 Dim MyValue, MyFindNext
 MyValue = InputBox("Company Name", "FAX / E-MAIL DATABASE")
 If MyValue = "" Then
 [C3].Select
 Exit Sub
 End If
 
 On Error GoTo err_Trap
 
 Worksheets("ORGINAL ").Columns(3).Find(What:=MyValue).Activate
 
 MyFindNext = vbYes
 
 Do Until MyFindNext <> vbYes
 MyFindNext = MsgBox("Next " & MyValue & "?", _
 vbYesNo, "Find Next")
 
 If MyFindNext = vbNo Then
 Exit Sub
 End If
 
 Worksheets("ORGINAL ").Columns(3).FindNext(after:=ActiveCell).Activate
 Loop
 
 Exit Sub
 
 err_Trap:
 
     i = 1
     If Err.Number = 91 Then
     
         MsgBox "Could not find " & MyValue & " anywhere on this sheet.", , "Unsuccessful search"
     
         End If
       
        MyValue = InputBox("Company Name", "FAX / E-MAIL DATABASE")
 Do
 i = i + 1
 Loop   
  
 
  
  
 
     If MyValue = "" Then
 [C3].Select
 Exit Sub
 End If
 Worksheets("ORGINAL ").Columns(3).Find(What:=MyValue).Activate
 
 
 MyFindNext = vbYes
 
 Do Until MyFindNext <> vbYes
 MyFindNext = MsgBox("Next " & MyValue & "?", _
 vbYesNo, "Find Next")
 
 
 If MyFindNext = "" Then
 Exit Sub
 End If
 
 If MyFindNext = vbNo Then
 Exit Sub
 End If
 
 Worksheets("ORGINAL ").Columns(3).FindNext(after:=ActiveCell).Activate
 Loop
 
 End Sub
 

Last edited by Shadow Wizard : January 30th, 2005 at 06:58 AM. Reason: added code tags - please do it yourself with [code] and [/code] tags next.

Reply With Quote
  #2  
Old January 29th, 2005, 09:18 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
Can't you just step through your code with the debugger and find out where it fails?
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old January 30th, 2005, 06:32 AM
Don D. Heeter Don D. Heeter is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 Don D. Heeter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 2 sec
Reputation Power: 0
Send a message via AIM to Don D. Heeter
Quote:
Originally Posted by Doug G
Can't you just step through your code with the debugger and find out where it fails?


Worksheets("ORGINAL ").Columns(3).Find(What:=MyValue).Activate


It always stops at this line, but since I still don't know what to do.
I have put the code in so many different places trying to solve the problem but nothing has worked.
That is why I thought I would ask for some help.
Thank you

Last edited by Shadow Wizard : January 30th, 2005 at 07:01 AM. Reason: removed the duplicate part.

Reply With Quote
  #4  
Old January 30th, 2005, 07:37 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
When you say "errors out" what is the error message?

I don't do much Excel VBA coding (well, none, actually ) but perhaps the error message will give a clue.

Reply With Quote
  #5  
Old January 30th, 2005, 08:44 PM
Don D. Heeter Don D. Heeter is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 Don D. Heeter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 2 sec
Reputation Power: 0
Send a message via AIM to Don D. Heeter
Thank you for your help.

Here is the message.

Run-Time Error 91
Object Variable or with block variable not set.

It should be able to loop in the Err-Trap, but I can not get it to.
Thank you.

Reply With Quote
  #6  
Old January 30th, 2005, 10:10 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
Do
i = i + 1
Loop

This code in your err_trap routine makes no sense to me.

Also review the flow of your program code. I don't quite understand how you ever get to the code at the bottom after the err_trap ends.

Reply With Quote
  #7  
Old January 31st, 2005, 11:28 AM
Don D. Heeter Don D. Heeter is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 Don D. Heeter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 2 sec
Reputation Power: 0
Send a message via AIM to Don D. Heeter
That has to be a error made by me.

Since I am not very good with VBA, I am not surprised that I put something in there that does not make any sense.
See if you can copy my code into a Excel sheet (rename sheet 1 to Orginal and put the data in column C) and put something in the cells for it to search (Like A B C in three different cells) for and then you can see it work when you type in something that is in the sheet, then type in something that is not on the sheet and do this twice and you will see the error that I told you about.
I got the code i = 1 Do i = i + 1 Loop from a Excel Marco book under The Do Loop section.
This was my dumb attempt at trying to do it on my own, I keep trying to learn.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Loop Question?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT