This seems simple, yet I can't find how you do this. I need to run a query in VB on a very simple database. There is the possibility that the query would be unsuccessfull, and if so I need to do other actions, but I can't seem to figure out how to check for this and run other code, I just get a Runtime Error '3061' Too few parameters. Expected 1.
Here is my code:
Dim MailDB As Database
Dim RS As Recordset
Dim SQL, eValue, PostieConfig, PP As String
' ----------------- '
'if notify hasn't been set, use default value
' ----------------- '
If notify = "" Then
notify = "System"
End If
' ----------------- '
' Open the Database on the Scheduler (currently NM16)
' ----------------- '
Set MailDB = OpenDatabase("\\ORMNM16\DB$\email.mdb")
' ----------------- '
' SQL will retrive all email addresses
' matching system table and notify columns
' ----------------- '
SQL = "Select Email From " & system & " Where " & notify & "=True"
Set RS = MailDB.OpenRecordset(SQL)
' ----------------- '
' Verify a record exists and retrive first address
' ----------------- '
If Not RS.EOF Then
If Not RS!Email = "" Then
eValue = RS!Email
Else
eValue = "nadcops@flowserve.com"
notify = notify + " Not Found in Email Database"
End If
End If
MsgBox eValue
' ----------------- '
' Loop through rest of addresses until verfication is complete
' ----------------- '
Do While Not RS.EOF
RS.MoveNext
If Not RS.EOF Then
eValue = eValue + "," + RS!Email
End If
Loop
' ----------------- '
' Close Database and Recordset
' ----------------- '
RS.Close
MailDB.Close
::
See I need to query the database to know who needs to get the email, dependent on notify returning true, and this works great if the script that calls this has a valid notify value.
But there is a very very good chance that someone would put the wrong notify value in, or not include it in the DB, and what I would like to do, is if the query returns nothing to check for that so I can do other things (like send me an email saying this notify value doesn't exist in the DB)