Boolean checking

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2006
Posts: 39
Reputation: INI is an unknown quantity at this point 
Solved Threads: 0
INI INI is offline Offline
Light Poster

Boolean checking

 
0
  #1
Jun 15th, 2006
Hi Guys,

Below is a code that searches for a value in a cell in excel. I want a code that would check to see if the word has been found or not. When I do the search and the word is not found, I get an error message " Object Variable or With block variable not set".

I know the above message comes up only when the word is not found. How can I by pass this inorder to tell the user through a message box that the document does not exist. That way the will be able to create a new record.



Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. word = frmSearch.txtEnterDate.Text
  2. If frmSearch.cboSystems.ListIndex = 0 Then
  3. Sheets("Current").Select
  4. Range("A1").Select
  5. 'Selection.End(xlDown).Select
  6. Range("A1:A65536").Find(What:=word, LookAt:=xlWhole, LookIn:=xlValues, SearchOrder:=xlByColumns).Activate


INI
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 39
Reputation: INI is an unknown quantity at this point 
Solved Threads: 0
INI INI is offline Offline
Light Poster

Re: Boolean checking

 
0
  #2
Jun 15th, 2006
Never mind guys , I think I figured it out ! I had to insert the error handler and it work.



Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim power As Variant
  2. word = frmSearch.txtEnterDate.Text
  3. If frmSearch.cboSystems.ListIndex = 0 Then
  4. Sheets("Current").Select
  5. Range("A1").Select
  6. 'Selection.End(xlDown).Select
  7. On Error GoTo ErrorHandler
  8. Range("A1:A65536").Find(What:=word, LookAt:=xlWhole, LookIn:=xlValues, SearchOrder:=xlByColumns).Activate
  9. ErrorHandler:
  10. power = CVErr(Err.Number)
  11. If IsError(power) Then
  12. MsgBox ("Word not found")
  13. End If
  14.  
  15. End If
Last edited by INI; Jun 15th, 2006 at 11:40 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 39
Reputation: INI is an unknown quantity at this point 
Solved Threads: 0
INI INI is offline Offline
Light Poster

Re: Boolean checking

 
0
  #3
Jun 15th, 2006
I have seen people cut an paste screen shots in the threads, how is taht done?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Boolean checking

 
0
  #4
Jun 15th, 2006
ctrl-printscreen seems to copy a screenshot (in XP anyways) to the clipboard..... then you can run mspaint (start run mspaint) and paste it into paint, in which case you can manip the image...... then when posting your thread (in advanced mode) there is an option to attach a file.... save the file in mspaint and attach it in the thread.....voila.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 39
Reputation: INI is an unknown quantity at this point 
Solved Threads: 0
INI INI is offline Offline
Light Poster

Re: Boolean checking

 
0
  #5
Jun 15th, 2006
Never mind guys , I think I figured it out ! I had to insert the error handler and it work.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim power As Variant
  2. word = frmSearch.txtEnterDate.Text
  3. If frmSearch.cboSystems.ListIndex = 0 Then
  4. Sheets("Current").Select
  5. Range("A1").Select
  6. 'Selection.End(xlDown).Select
  7. On Error GoTo ErrorHandler
  8. Range("A1:A65536").Find(What:=word, LookAt:=xlWhole, LookIn:=xlValues, SearchOrder:=xlByColumns).Activate
  9. ErrorHandler:
  10. power = CVErr(Err.Number)
  11. If IsError(power) Then
  12. MsgBox ("Word not found")
  13. End If
  14.  
  15. End If
Last edited by Comatose; Jun 15th, 2006 at 8:16 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2206 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC