Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expected Statement

Status
Not open for further replies.

coachdan

MIS
Mar 1, 2002
269
US
I had a logic error in a portion of code that I am trying to straighten out. I have rewritten the code but I am getting an Expected Statement error. The logic needs to be that if "Citi" is selected from the varBusName dropdown, it needs to look at the year selected in the varYrA dropdown and choose the correct db to transfer the data to. If "Sears" is selected, then it should look to the varYrA for a year and choose from a different set of db's. Am I missing an "end if" or something?

Code:
If varBusName = "Citi" Then
If varYrA = "2002" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2003" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data03.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2004" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data04.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2005" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data05.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2006" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data06.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2007" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data07.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2008" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data08.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2009" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data09.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2010" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data10.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

If varBusName = "Sears" Then

If varYrA = "2002" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_DataSears.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2003" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data03Sears.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2004" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data04Sears.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2005" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data05Sears.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2006" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data06Sears.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2007" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data07Sears.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2008" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data08Sears.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2009" Then

	Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=" & Server.Mappath("Training_Delivery_Data09Sears.mdb") & ";"

	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

Else

If varYrA = "2010" Then

   Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   	& "Data Source=" & Server.Mappath("Training_Delivery_Data10Sears.mdb") & ";"

   	SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

   	Set uRS = Server.CreateObject("ADODB.Recordset")
	uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic

End If

End If

coachdan32

 
I am no expert on ASP, but I think you need an ELSE for the variables Citi and Sears....

When in doubt, deny all terms and defnitions.
 
hi,
u can hae only one ELSE but u seem to have many...

Known is handfull, Unknown is worldfull
 
This looks like the same code that we simplified in thread253-698267 , but returned to it's previous, repetitive, hard-to-follow format. Pick out the thing that changes for each possible set of values - in this case the database name - put that in the If/Then/Else or Case statements, put the rest in one place afterwards. The result will be much easier to read, easier to maintain and less prone to syntax errors like "Statement Expected" (which means you've put something else where VBScript expects a statement).

Here's a simplified approach (again!) which may help:
[tt]
If varBusName = "Citi" Then
Select Case varYrA
Case "2002"
varDB = "Training_Delivery_Data.mdb"
Case "2003"
varDB = "Training_Delivery_Data03.mdb"
' Other cases in here
End Select
Else
Select Case varYrA
Case "2002"
varDB = "Training_Delivery_DataSears.mdb"
Case "2003"
varDB = "Training_Delivery_Data03Sears.mdb"
' Other cases in here
End Select
End If

Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.Mappath(varDB) & ";"

SQLAdd = " SELECT * FROM Trainers WHERE Trainers.TId LIKE '%"& Request.Form("TId") &"%'"' "

Set uRS = Server.CreateObject("ADODB.Recordset")
uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic
[/tt]

-- Chris Hunt
 
Chris,

I reposted because after our last post in Thread253-698267 , I was still getting the same error message and I was confused as to why I was getting it on some and not on others. I have retried your idea (which as I posted before that I agreed made a lot more sense) and am a alot closer to making it work. I am getting an error still, but a different one.

error '80040e21'
Field cannot be updated.

I am now trying to find the reason for this, but want to try to work it out for myself. I know I post a lot on this forum, but I am new and as I have said before, I am working in a one man shop with no where else to go for help. I am very appreciative of those who give of their time to assist and apologize if you felt I was ignoring your suggestion. Truth be told, I have 3 versions of this thing on my desktop that I am trying different solutions on at the same time.

coachdan32

 
Working on three versions at once sounds like a recipe for confusion, but that's your call. As I said before, I don't really speak VBscript so I can't address your actual problem, but here's a couple of pointers for making the most of this forum:

1) Choose the right forum - since your question is about vbscript, post it in the vbscript forum: forum329 .

2) Try not to post HUGE chunks of code, not everyone has the patience to download and plough through it all. Maybe you could put your whole script in a .txt file on your server and link to it, then just post the snippet that's giving the error.

3) Post full information about any error message you receive, "an Expected Statement error" is really vague, do you have any more information? Critically, we need to know the line where the error occurs (especially when you post half a mile of code!). If you're not getting that info already, no doubt the vbscript forum guys can tell you how to find it.

Fun this programming lark ain't it?

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top