code_junkie

vbscript: test for existence of a column in a recordset

Nov 14th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. if (not rsObject("columnNameThatDoesntExist") is nothing) then
  2. ' do some stuff
  3. end if
  4. ' else do nothin
  5.  
  6. blnItWasntThere = True
  7. On Error Resume Next
  8. If (rsObject("columnNameThatDoesntExist") <> "") Then
  9. blnItWasntThere = False
  10. ...
  11. ...
  12. ...
  13. End If
  14. On Error Goto 0
  15.  
  16. If blnItWasntThere Then
  17. 'handle this error'
  18. End If
  19.  
  20. Function ColumnExists(objRS, Column)
  21. Dim blnOutput, x
  22. blnOutput = False
  23. On Error Resume Next
  24. x = objRS(Column)
  25. If err.Number <> 0 Then blnOutput = True
  26. On Error Goto 0
  27. ColumnExists = blnOutput
  28. End Function
  29.  
  30. Dim oRs:Set oRs = Nothing
  31. On Error Resume Next
  32. Set oRs = rsObject("columnNameThatDoesntExist")
  33. On Error Goto 0
  34. If Not rsObject("columnNameThatDoesntExist" Is Nothing Then
  35. ' ...
  36. End If
Add Comment
Please, Sign In to add comment