Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL and RecordSets 1

Status
Not open for further replies.

seema165

Programmer
Jul 11, 2005
48
0
0
GB
Hi,

I have a error in my code when I run it. In the following code, if the where statement doesn't return anything I get an error.

Here's the code:

while not objRecordSet.EOF
strSQL = "SELECT bhagnb FROM mvxjdta.staghe WHERE bhagnb = ('" & objRecordSet(0) &"'))"
objRS = objConnection.Execute(strSQL)
MsgBox objRecordSet(0), vbOKOnly, "1st"
MsgBox objRS(0), vbOKOnly, "2nd"
if (objRecordSet(0) = objRS(0) )Then
intRecordSet = objRS.Count
MsgBox intRecordSet, vbOKOnly, "Count Record"
End If
objRecordSet.MoveNext
Wend

The error occurs at 'MsgBox objRS(0), vbOKOnly, "2nd" ' and at 'if (objRecordSet(0) = objRS(0) )Then ' lines. What I want to do is, if the select statement doesn't bring back anything then I want to output a message (this is not in the above code)

Please help, this is a problem I have had for a while now.

Thanks.
 
try this...
Code:
[red]If NOT objRecordSet.EOF Then[/red]
  while not objRecordSet.EOF
    strSQL = "SELECT bhagnb FROM mvxjdta.staghe WHERE bhagnb = ('" & objRecordSet(0) &"'))"
     objRS = objConnection.Execute(strSQL)   

     [red]If NOT objRS.EOF Then[/red]       
       MsgBox objRecordSet(0), vbOKOnly, "1st"
       MsgBox objRS(0), vbOKOnly, "2nd"
       if (objRecordSet(0) = objRS(0) )Then
         intRecordSet = objRS.Count
         MsgBox intRecordSet, vbOKOnly, "Count Record"
       End If
     [red]Else
         'display message here[/red]
     [red]End If[/red]
     objRecordSet.MoveNext
  Wend
[red]Else
'display message here
End If[/red]

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
Hi Tony,

I'm getting error message saying: Object doesn't support this property or method: 'objRS.EOF'
 
Hi Tony,

I'm getting error message saying: Object doesn't support this property or method: 'objRS.Count'
 
It gives me the same error when I use objRS.RecordCount
 
Tony,

It works now with RecordCount. I think it didn't work before because I didn't restart my application.

Thanks for the help ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top