944,196 Members | Top Members by Rank

Ad:
Jun 15th, 2006
0

Boolean checking

Expand Post »
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
Similar Threads
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
Jun 15th, 2006
0

Re: Boolean checking

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.
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
Jun 15th, 2006
0

Re: Boolean checking

I have seen people cut an paste screen shots in the threads, how is taht done?
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
Jun 15th, 2006
0

Re: Boolean checking

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jun 15th, 2006
0

Re: Boolean checking

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.
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: error handling in VB6 + + ODBC + MySQL...(Help!!!!)
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Sort a dynamic array of structs





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC