Link to home
Start Free TrialLog in
Avatar of wharris26
wharris26

asked on

How to make a custom error when no record is found on an aspvbscript page using dreamweaver.

I need to make a custom error message for the following error using dreamweaver on an aspvbscript page.
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

trick is simple


if NOT RS.EOF then

 ' Process your code here

End if

in above example i assume RS is the recordset object.

above line also means if we have "some" records then do something within if statement, otherwise dont return anything from database.

The custom error message is  as follows...

I not rsData.EOF Then

Run your scripts...

Else

Response.write("Sorry, there are no records to view")

End If

Hope this helps.

Aplimedia
Avatar of wharris26
wharris26

ASKER

So is this what it should look like?
Recordset1.Source = "SELECT * FROM otpt.SIOT WHERE SID = " + Replace(Recordset1__MMColParam, "'", "''") + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
IF NOT Recordset1.EOF THEN
Recordset1_numRows = 0
ELSE
RESPONSE.Write("No Records were found")
END IF
IF so I have 2 problems, 1 the browser gives internet friendly error messages not the script I wrote and I still get an error because I have a second recordset that is dependent of the value from the first recordset.  How do I deal with that.
ASKER CERTIFIED SOLUTION
Avatar of aplimedia
aplimedia
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The error might be because of somthing else you are doing on th epage... What is the eror?

Aplimedia
I think the problem is definitely the second recordset.  I did what you said, it looks like this:

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_OTPT_STRING
Recordset1.Source = "SELECT * FROM otpt.SIOT WHERE SID = " + Replace(Recordset1__MMColParam, "'", "''") + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
IF NOT Recordset1.EOF THEN
Recordset1_numRows = 0

Recordset2.Source = "SELECT *  FROM dbo.SchoolLookup  WHERE SchoolID = " + Replace(Recordset2__MMColParam2, "'", "''") + ""
Recordset2.CursorType = 0
Recordset2.CursorLocation = 2
Recordset2.LockType = 1
Recordset2.Open()
IF not Recordset1.EOF THEN
Recordset2_MMColParam2 = Recordset1("SchoolID")
ELSE
END IF
ELSE
RESPONSE.WRITE("NO RECORDS FOUND")
END IF

The error still occurs when Recordset2 variables are defined later in the page:  Looks like this
Dim Recordset2__MMColParam2
Recordset2__MMColParam2 = "1"
If (Recordset1("SchoolID") <> "") Then
  Recordset2__MMColParam2 = Recordset1("SchoolID")

 End If
Can I just address the problem here?
If you don't tell me the error you are getting, i will not be able to help you...

Copy and paste it here

Aplimedia


...Recordset2.LockType = 1
Recordset2.Open()
IF not Recordset1.EOF THEN <<<<<<<<<<<<<<<<  This should be.. IF not Recordset2.EOF THEN
Recordset2_MMColParam2 = Recordset1("SchoolID")
ELSE
END IF
...
NO RECORDS FOUND error '80020009'
/ese/otpt/OTPTDynamic/SearchResultsOT.asp, line 40
Line 40 is as follows:
Dim Recordset2__MMColParam2
Recordset2__MMColParam2 = "1"
If (Recordset1("SchoolID") <> "") Then
  Recordset2__MMColParam2 = Recordset1("SchoolID")
 End If

Change the line...

IF not Recordset2.EOF THEN

to

IF not Recordset2.EOF THEN And Not Recordset2.BOF then


Let me know..

Aplimedia

New Error:
Microsoft VBScript compilation error '800a0400'

Expected statement

/ese/otpt/OTPTDynamic/SearchResultsOT.asp, line 29

IF not Recordset2.EOF THEN AND NOT Recordset2.BOF Then
---------------------------^
Ok...

One too many then's... cahneg line.

IF not Recordset2.EOF THEN AND NOT Recordset2.BOF Then

to

IF not Recordset2.EOF AND NOT Recordset2.BOF Then


Aplimedia
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Back to original error.
Thank you for your help.  I have increased it to 500 points, however it remains the same question and I do not believe it has digressed.   I still need an custom error message for when no records are returned.  It is only complicated by having a second dependent recordset.  I thought it would be much easier to answer.
I added Response.End() under the Response Write and that stopped the code to keep the error from occuring.