Where is invisible problem in the code here?
-
Hello! This sample procedure extracts email addresses and adds to database. However, it is successfully adding the first address and creating empty records for the others. I decided to test the procedure with vb.net and took out adding the database section. It worked perfectly. So I would like to know what is causing not to add other emails except the first one. Thank You Sub AddEmails() Dim GetEmails Dim SrchKey Dim xPos Dim x1, x2 Dim xAddr GetEmails = Request.Form("emails") xPos = 1 x1=Instr(xpos,GetEmails,VbCrLf) DO WHILE xpos <= len(Getemails) x1=Instr(xPos,GetEmails,vbCrLf) x2=Instr(xPos+1 ,GetEmails,vbCrLf) If x1 = 0 or x2 = 0 Then Exit Do If xPos = 1 Then xAddr = Mid(GetEmails,1,x1-1) Elseif xpos > 1 Then xAddr = Mid(GetEmails, x1, x2 - x1) End If If len(xAddr) > 4 Then 'check here if email address is not exist in the database SrchKey = "SELECT * FROM emails WHERE email="& "'" & xAddr & "';" Call InitializeConnection() Call Establish_Recording(SrchKey) If ObjectRecord.RecordCount <= 0 Then ObjectRecord.Close ObjectConnection.Close Set ObjectRecord = Nothing Call InitializeConnection() Call InitializeRecordSet("Emails") 'PROBLEM IS CAUSED BY THE FOLLOWING STATEMENTS 'IT IS ADDING THE FIRST ADDRESS BUT NOT THE OTHERS ObjectRecord.AddNew ObjectRecord("email") = xAddr ObjectRecord("Accept") = True ObjectRecord.update ObjectRecord.Close ObjectConnection.Close Set ObjectRecord = Nothing
-
Hello! This sample procedure extracts email addresses and adds to database. However, it is successfully adding the first address and creating empty records for the others. I decided to test the procedure with vb.net and took out adding the database section. It worked perfectly. So I would like to know what is causing not to add other emails except the first one. Thank You Sub AddEmails() Dim GetEmails Dim SrchKey Dim xPos Dim x1, x2 Dim xAddr GetEmails = Request.Form("emails") xPos = 1 x1=Instr(xpos,GetEmails,VbCrLf) DO WHILE xpos <= len(Getemails) x1=Instr(xPos,GetEmails,vbCrLf) x2=Instr(xPos+1 ,GetEmails,vbCrLf) If x1 = 0 or x2 = 0 Then Exit Do If xPos = 1 Then xAddr = Mid(GetEmails,1,x1-1) Elseif xpos > 1 Then xAddr = Mid(GetEmails, x1, x2 - x1) End If If len(xAddr) > 4 Then 'check here if email address is not exist in the database SrchKey = "SELECT * FROM emails WHERE email="& "'" & xAddr & "';" Call InitializeConnection() Call Establish_Recording(SrchKey) If ObjectRecord.RecordCount <= 0 Then ObjectRecord.Close ObjectConnection.Close Set ObjectRecord = Nothing Call InitializeConnection() Call InitializeRecordSet("Emails") 'PROBLEM IS CAUSED BY THE FOLLOWING STATEMENTS 'IT IS ADDING THE FIRST ADDRESS BUT NOT THE OTHERS ObjectRecord.AddNew ObjectRecord("email") = xAddr ObjectRecord("Accept") = True ObjectRecord.update ObjectRecord.Close ObjectConnection.Close Set ObjectRecord = Nothing
-
This is just a guess. Wouldn't the ( xAddr="" ) set a blank each time the program made a loop?
Hello! Thanks for your respond. Xaddr returns a value eact time in the loop. I have tested the code with vb.net. I think having connection to database or recordset inseide the loop is causing the problem even though connection is getting closed and object record set to nothing.