I’m trying to query a SQL database from vbs but when no record is found I get an error
ADODB.Field : Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
I think I need to use an IF NOT statement to capture if the record isn’t found but I can’t figure out where it needs to go.
Do Until objFile.AtEndofStream
strAppName = objFile.ReadLine
ConnString="DRIVER={SQL Server};SERVER=aardvark002;UID=***;PWD=***;DATABASE=DEW_Users"
SQL = "USE Win7AppData SELECT " & Chr(34) & strCountry & Chr(34) & " FROM AppsByCountry WHERE Application = '" & strAppName & "'"
Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
Connection.Open ConnString
Recordset.Open SQL,Connection
strApproval = Recordset(strCountry)
If StrApproval = "YES" Then
strApproval = "Approved"
Else
strApproval = "Denied"
End If
objExcel.Cells(intRow, 1).Value = strAppname
objExcel.Cells(intRow, 2).Value = strCountry
objExcel.Cells(intRow, 3).Value = strApproval
intRow = intRow + 1
Loop
Bit rusty on my VBScript, but you should be able to use .EOF on the Recordset to check if it’s at the end:
W3Schools reference