Can someone help me get this sub to exit correctly?

T

Teep

Where there is a duplicate invoice, I want to stop the process and
post to the user on the same page and not continue to the next
page...I tried Return or Exit Sub...but still the same thing occurs.

Sub Close1Open2(Source as Object, E as EventArgs)
pnl1.visible="false"
pnl2.visible="false"
pnl3.visible="false"
pnl4.visible="true"

Dim strConn as string =
"server=abcd;database=cds;trusted_connection=true"
Dim MySQL as string = "Select supplier_cd, inv_no, inv_date from
view_cds_all where supplier_cd='" & txtSupCD.text & "' and inv_no='" &
txtInvNum.text & "' and inv_date='" & txtInvDate.text & "'"
Dim MyConn as New SQLConnection(strConn)
Dim objDR as SQLDataReader
Dim Cmd as New SQLCommand(MySQL, MyConn)
MyConn.Open()
objDR=Cmd.ExecuteReader()
While objDR.Read()
If IsDbNull(objDR.GetString(0))=False Then
blHasRows="True"
else
blHasRows="False"
End If
End While
MyConn.Close()

MySQL = "Insert into a_p.dbo.tbl_ap_web_ce_inv_terms (splr_cd,
inv_numb, inv_dat) Values ('" & txtSupCD.text & "','" & txtInvNum.text
& "'," & txtInvDate.text & ")"
Dim Cmd2 as New SQLCommand(MySQL, MyConn)
if blHasRows="False" then
MyConn.Open()
Cmd2.ExecuteNonQuery()
lblResults.text="Your information has been received!"
MyConn.Close
else
lblResults.text="Sorry, that information is already in the
database"
End If
End Sub
 
R

Rick Spiewak

You aren't showing the code that redirects to the next page, which is where
you would need to detect and act on the difference. If you're calling this
sub from that code, try making it a function and return a boolean indicating
whether to continue or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top