Lee-yoshi 3 Posted July 9, 2010 Report Share Posted July 9, 2010 HiI have a VERY ANNOYING problem!Below is the code (I've edited out all names etc with #'s - Pretend there's just normal names there if you will) and when trying to run it Internet Explorer constantly gives me the error:Microsoft VBScript compilation error '800a040e' 'loop' without 'do' /test_maccess_update.asp, line 130 loop^I can only assume it's because there's an If statement that hasn;t been correctly closed or something. But i've checked and checked and checked and i can't find anything wrong whatsoever!!!!If you can help i'd be so amazingly grateful you wouldn't believe!I've attached my code below: dim Change Change = 0 set DatabaseConnection = Server.CreateObject("ADODB.Connection") DatabaseConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("#######.mdb") set Records = Server.CreateObject("ADODB.recordset") set DatabaseConnection2 = Server.CreateObject("ADODB.Connection") DatabaseConnection2.Open "DRIVER={MySQL ODBC 3.51 Driver};" &_ "SERVER=###########;" &_ "Port=####;" &_ "DATABASE=###########;" &_ "UID=###########;" &_ "PWD=##########;" set Records2 = Server.CreateObject("ADODB.recordset") Records.Open "SELECT * FROM ########", DatabaseConnection do until Records.EOF Records2.Open "SELECT Count(*) AS RecordsCount FROM ########## WHERE Barcode='" & Records.fields("#######").value & "' AND #######='" & Records.fields("#######").value & "' AND ######='" & Records.fields("######").value & "'", DatabaseConnection2 if Records2("RecordsCount") > 0 Then sql="UPDATE ####### SET" if Records.fields("#######") <> Records2.fields("#######") Then sql=sql & " #######='" & Records.fields("#######") & "'," Change = 1 end if if Records.fields("#####") <> Records2.fields("#####") Then sql=sql & " #####='" & Records.fields("#####") & "'," Change = 1 end if if Records.fields("#####") <> Records2.fields("#####") Then sql=sql & " #####='" & Records.fields("#####") & "'," Change = 1 end if if Records.fields("########") <> Records2.fields("########") Then sql=sql & " ########='" & Records.fields("########") & "'," Change = 1 end if if Change = 1 Then sql=sql & " ########='#' " sql=sql & " WHERE #####='" & Records.fields("#######").value & "' AND " sql=sql & "########='" & Records.fields("#########").value & "' AND " sql=sql & "######='" & Records.fields("#######").value & "'" else sql = "" end if else if Records2("RecordsCount") = 0 Then if Change = 0 Then sql = "" end if sql="INSERT INTO Catalog (#########,########,###########,###########," sql=sql & "####,####,#####,####,######,######,######,########,#####," sql=sql & "#######,###########,##########,#######,########) VALUES " sql=sql & "('" & Records.fields("########").value & "'," sql=sql & "'" & Records.fields("##########").value & "'," sql=sql & "'" & Records.fields("##########value & "'," sql=sql & "'" & Records.fields("##########").value & "'," sql=sql & "'" & Records.fields("########").value & "'," sql=sql & "'" & Records.fields("#####").value & "'," sql=sql & "'" & Records.fields("##############").value & "'," sql=sql & "'" & Records.fields("########").value & "'," sql=sql & "'" & Records.fields("#######").value & "'," sql=sql & "'" & Records.fields("###########").value & "'," sql=sql & "'" & Records.fields("#########").value & "'," sql=sql & "'" & Records.fields("#######").value & "'," sql=sql & "'" & Records.fields("##########").value & "'," sql=sql & "'" & Records.fields("#########").value & "'," sql=sql & "'" & Records.fields("########").value & "'," sql=sql & "'" & Records.fields("######").value & "'," sql=sql & "'#','######')" Change = 2 end if if Change = 1 OR Change = 2 Then on error resume next DatabaseConnection2.Execute sql, recaffected if err<>0 then Response.Write("An error has occured") else Response.Write("<br>") if Change = 0 Then Response.Write("#####" & Records.fields("##").value & ") ") Response.Write( Records.fields("####").value & "' - '") Response.Write( Records.fields("#####").value & "'#########") sql = "" else if Change = 1 Then Response.Write("#######' "& Records.fields("######").value & "' - '") Response.Write( Records.fields("#####").value & "' #####") sql = "" Change = 0 end if end if end if Records.MoveNext loop Records.close DatabaseConnection.close Records2.Open "SELECT Count(*) AS RecordsCount2 FROM ###### WHERE ########='##########' AND #####='#'", DatabaseConnection2 if Records2("RecordsCount2") > 0 Then sql = "UPDATE ##### SET ############='#',#####='#' " sql = sql & "WHERE ########='#' AND ######='#'" on error resume next DatabaseConnection2.Execute sql, recaffected if err<>0 then Response.Write("An error has occured") else Response.Write("######" & Records.fields("#").value & ") ") Response.Write( Records.fields("######").value & "' - '") Response.Write( Records.fields("#####").value & "' #####") sql = "" end if end if Records2.close DatabaseConnection2.close Basically what the code is doing (Should you be interested) is importing changed data from an Access file into an SQL database. Well, that's what it should do anyways... Quote Link to post Share on other sites
justsomeguy 1,135 Posted July 12, 2010 Report Share Posted July 12, 2010 When you use else if the end if doesn't apply to the first if, only the second. Instead of a structure like this: if Change = 0 Then ...else if Change = 1 Then ...end if you need to do this: if Change = 0 Then ...else if Change = 1 Then ... end ifend if Each if statement needs an end if. If you're going to chain if statements onto else statements, make sure you end each one properly. Quote Link to post Share on other sites
Lee-yoshi 3 Posted July 13, 2010 Author Report Share Posted July 13, 2010 Ah i see. Works now :)justsomeguy... i think i love you!Many, many thanks! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.