473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ASP & MS ACCESS if condition error ?

Fary4u
273 100+
Hi i've got this following error any body knows how to overcome this coz it's waste my 3 hours

Error Type:
Microsoft VBScript compilation (0x800A03F6)
Expected 'End'

line 58

is my if condition have something wrong ?

it's multiple data entry record into the database ?

Expand|Select|Wrap|Line Numbers
  1. <%
  2. pnam=Trim(request("txtpname"))
  3. Set objConn = Server.CreateObject("ADODB.Connection")
  4. objConn.open . . . . MS ACCESS
  5. set objrs = server.createObject("ADODB.RecordSet")
  6. objrs.open "Select productName from products where productName='" & pnam & "'",objConn,Adopendynamic,Adlockoptimistic
  7. if objrs.eof then
  8.  
  9.     pnam=Trim(request("txtpname"))
  10.     tdes=Trim(request("txtdesc"))
  11.     prid=Trim(request("txtpid"))
  12.  
  13.         if (categ = "") then
  14.         response.redirect "ul_add.asp"
  15.         end if
  16.  
  17.             objrs.Addnew
  18.                 objrs("productName")=pnam
  19.                 objrs("productDesc")=tdes                                
  20.             objrs.update
  21.  
  22.             st2 = Request.Form("10")
  23.             st3 = Request.Form("12")
  24.             ct1 = Request.Form("black")
  25.             ct2 = Request.Form("blue")
  26.  
  27.     Set Conn = Server.CreateObject("ADODB.Connection")
  28.     Conn.Open ConString    
  29.  
  30.         If st1 = "10" Then
  31.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  32.                     & " (size_id, prod_id) values " _ 
  33.                     & " ('10',"&prid&")"
  34.                 Conn.Execute(sqlText)
  35.         else if st2 = "12" Then
  36.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  37.                     & " (size_id, prod_id) values " _ 
  38.                     & " ('12',"&prid&")"
  39.                 Conn.Execute(sqlText)
  40.         else if ct1 = "black" Then
  41.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  42.                 & " (color_id, prod_id) values " _ 
  43.                 & " ('black',"&prid&")"
  44.             Conn.Execute(sqlText)
  45.         else if ct2 = "blue" Then
  46.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  47.                 & " (color_id, prod_id) values " _ 
  48.                 & " ('blue',"&prid&")"
  49.             Conn.Execute(sqlText)
  50.         response.write "New Record save in the Database"
  51. else
  52.         response.write "This Record already in a Database"
  53. end if
  54.  
  55. objrs.close
  56. set objrs= Nothing
  57. objConn.Close
  58. set objConn = Nothing
  59. %>
  60.  
any solution for that ?
Oct 18 '07 #1
9 2799
markrawlingson
346 Expert 100+
Look at this block of code...

Expand|Select|Wrap|Line Numbers
  1.         If st1 = "10" Then
  2.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  3.                     & " (size_id, prod_id) values " _ 
  4.                     & " ('10',"&prid&")"
  5.                 Conn.Execute(sqlText)
  6.         else if st2 = "12" Then
  7.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  8.                     & " (size_id, prod_id) values " _ 
  9.                     & " ('12',"&prid&")"
  10.                 Conn.Execute(sqlText)
  11.         else if ct1 = "black" Then
  12.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  13.                 & " (color_id, prod_id) values " _ 
  14.                 & " ('black',"&prid&")"
  15.             Conn.Execute(sqlText)
  16.         else if ct2 = "blue" Then
  17.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  18.                 & " (color_id, prod_id) values " _ 
  19.                 & " ('blue',"&prid&")"
  20.             Conn.Execute(sqlText)
  21.         response.write "New Record save in the Database"
  22. else
  23.         response.write "This Record already in a Database"
  24. end if
  25.  
  26.  
Replace it with the following (i pointed out the error here too)

Expand|Select|Wrap|Line Numbers
  1.         If st1 = "10" Then '<-- the code is expecting an end to this statement
  2.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  3.                     & " (size_id, prod_id) values " _ 
  4.                     & " ('10',"&prid&")"
  5.                 Conn.Execute(sqlText)
  6.         else if st2 = "12" Then
  7.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  8.                     & " (size_id, prod_id) values " _ 
  9.                     & " ('12',"&prid&")"
  10.                 Conn.Execute(sqlText)
  11.         else if ct1 = "black" Then
  12.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  13.                 & " (color_id, prod_id) values " _ 
  14.                 & " ('black',"&prid&")"
  15.             Conn.Execute(sqlText)
  16.         else if ct2 = "blue" Then
  17.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  18.                 & " (color_id, prod_id) values " _ 
  19.                 & " ('blue',"&prid&")"
  20.             Conn.Execute(sqlText)
  21.         end if '<---- was missing
  22.         response.write "New Record save in the Database"
  23. else
  24.         response.write "This Record already in a Database"
  25. end if '<--- Is the end to another If statement further up in the code.
  26.  
Sincerely,
Mark
Oct 18 '07 #2
Fary4u
273 100+
Thx for you kindly reply i've tryied that but the error i've found it on else statment when it's finally going to b finished ?

Line 23 the new code

? ? ? ? ? ? ? i don't know why ?

Regards
Farhan
Oct 19 '07 #3
Thx for you kindly reply i've tryied that but the error i've found it on else statment when it's finally going to b finished ?

Line 23 the new code

? ? ? ? ? ? ? i don't know why ?

Regards
Farhan
Hi , Farhan
Just put the "End If" after Line 25 and see what happens.

Thanks
Oct 22 '07 #4
JamieHowarth0
533 Expert 512MB
Hi Fary,

You might want to use Select Case to simplify your code instead of If and ElseIf. That way, (I personally find) it's easier to track any problematic code instead of trying to match opening and closing If... End If statements.

Best regards,

medicineworker
Oct 22 '07 #5
Fary4u
273 100+
Hi thx for the reply if i'm gonna try the case condition then it's skip few points which i'm trying to save into the database ?

so i just want to store it to selection if condition coz i think so it's more apporiate then case but any thing else is worng ?

coz i've tryed all possiblities but only give this error ?

Error Type:
Microsoft VBScript compilation (0x800A03F6)
Expected 'End'
/shop/admin/ul_confirm.asp, line ( last else statment )?
Oct 22 '07 #6
markrawlingson
346 Expert 100+
It may also be your if...else.. statement.

If...else... statements in ASP are not written with a space between them(Else If), they're written together (ElseIf). If they're written apart - I believe ASP may interpret them to be a seperate if statement, which also requires an end if statement. So ASP thinks you've got FOUR if statements here, not one else...if.. and is looking for an end if for all of them.

Expand|Select|Wrap|Line Numbers
  1. If whatever = whatever Then
  2. 'do whatever
  3. Else If whatever <> whatever then
  4. 'do something else
  5. end if
  6.  
  7. 'the above is the equivelant to the following..
  8.  
  9. If Whatever = whatever Then
  10. 'do whatever
  11. Else
  12.    If whatever <> whatever then
  13.      'do whatever
  14.    End If
  15.  
  16. 'See the missing end if? That's what ASP sees.
  17.  
Try the following code::

Expand|Select|Wrap|Line Numbers
  1. <%
  2. pnam=Trim(request("txtpname"))
  3. Set objConn = Server.CreateObject("ADODB.Connection")
  4. objConn.open . . . . MS ACCESS
  5. set objrs = server.createObject("ADODB.RecordSet")
  6. objrs.open "Select productName from products where productName='" & pnam & "'",objConn,Adopendynamic,Adlockoptimistic
  7. if objrs.eof then
  8.  
  9.     pnam=Trim(request("txtpname"))
  10.     tdes=Trim(request("txtdesc"))
  11.     prid=Trim(request("txtpid"))
  12.  
  13.         if (categ = "") then
  14.         response.redirect "ul_add.asp"
  15.         end if
  16.  
  17.             objrs.Addnew
  18.                 objrs("productName")=pnam
  19.                 objrs("productDesc")=tdes                        
  20.             objrs.update
  21.  
  22.             st2 = Request.Form("10")
  23.             st3 = Request.Form("12")
  24.             ct1 = Request.Form("black")
  25.             ct2 = Request.Form("blue")
  26.  
  27.     Set Conn = Server.CreateObject("ADODB.Connection")
  28.     Conn.Open ConString 
  29.  
  30.         If st1 = "10" Then
  31.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  32.                     & " (size_id, prod_id) values " _ 
  33.                     & " ('10',"&prid&")"
  34.                 Conn.Execute(sqlText)
  35.         elseif st2 = "12" Then
  36.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  37.                     & " (size_id, prod_id) values " _ 
  38.                     & " ('12',"&prid&")"
  39.                 Conn.Execute(sqlText)
  40.         elseif ct1 = "black" Then
  41.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  42.                 & " (color_id, prod_id) values " _ 
  43.                 & " ('black',"&prid&")"
  44.             Conn.Execute(sqlText)
  45.         elseif ct2 = "blue" Then
  46.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  47.                 & " (color_id, prod_id) values " _ 
  48.                 & " ('blue',"&prid&")"
  49.             Conn.Execute(sqlText)
  50.         end if
  51.         response.write "New Record save in the Database"
  52. else
  53.         response.write "This Record already in a Database"
  54. end if
  55.  
  56. objrs.close
  57. set objrs= Nothing
  58. objConn.Close
  59. set objConn = Nothing
  60. %>
  61.  
You wouldn't be able to use a Select case statement here. Select statements check the value of 1 variable, and do different things depending on what the value of that variable is. In each section of your if...else statement here you're checking a different variable, so a case statement would not be effective.

Try the code above and see if it works, the bottom line here is that ASP IS looking for an ending to one of your If statements, you just have to find where. I believe I've found it in the above code... so see if that works.

Sincerely,
Mark
Oct 22 '07 #7
Fary4u
273 100+
thanks for every body who's replying on this post

Marks you've rite if condition has some problem when i use
Expand|Select|Wrap|Line Numbers
  1.  elseif 
all together it's execuate all my code but it's only store the 1st value & then next values it's just skip the all values of my program


it mean after taking elseif it's jumped into the last endif statement but i want to use the other as well ?

please any body have some solution how to overcome this problem for the last many dayz i've ?

best regards
Farhan
Oct 23 '07 #8
markrawlingson
346 Expert 100+
Yeah, of course it will.

IF...ELSE statements are kind of like saying "If today is saturday, go partying, otherwise.. go to work."

Otherwise, being the keyword here.

You're basically saying If st1 = "10" Then - insert a record, otherwise (if st1 does NOT equal "10", then check to see if st2 = "12", if it is... insert a record pertinant to that variable.... If st2 does NOT equal "12" then check to see if ct1 = "black" - if it is, insert a record.. etc etc.

What you want to do is check each one individually.
See the below code.

Expand|Select|Wrap|Line Numbers
  1. <%
  2.         If st1 = "10" Then
  3.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  4.                     & " (size_id, prod_id) values " _ 
  5.                     & " ('10',"&prid&")"
  6.                 Conn.Execute(sqlText)
  7.         End If
  8.         If st2 = "12" Then
  9.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  10.                     & " (size_id, prod_id) values " _ 
  11.                     & " ('12',"&prid&")"
  12.                 Conn.Execute(sqlText)
  13.         End If
  14.         If ct1 = "black" Then
  15.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  16.                 & " (color_id, prod_id) values " _ 
  17.                 & " ('black',"&prid&")"
  18.             Conn.Execute(sqlText)
  19.         End If
  20.         If ct2 = "blue" Then
  21.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  22.                 & " (color_id, prod_id) values " _ 
  23.                 & " ('blue',"&prid&")"
  24.             Conn.Execute(sqlText)
  25.         End If
  26. %>
  27.  
This is different because it says,

If st1 = "10" - add a record - if it isn't, don't add a record
If st2 = "12" - add a record - if it isn't, don't add a record
If ct1 = "black" - add a record - if it isn't, don't add a record
etc.

Sincerely,
Mark
Oct 24 '07 #9
Fary4u
273 100+
Hi Marks thx for you replying
and all other how make contribution on this discussion

my coding is working fine thx for the discussion
can you please take a look this code as well any idea about that ?
http://www.thescripts.com/forum/thread695688.html

regards
Farhan
Oct 24 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
11
by: Arpan | last post by:
<% If(False) Then Response.Write("False") Else Response.Write("True") End If %> In the above code, the Else condition will be executed. Why?
2
by: kma | last post by:
I am designing an Access 2000 database on a computer running Windows 98. I have one form with several tabs; all of which have sub forms, some with a subform on a subform. For example, on my...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
42
by: Andy | last post by:
and so far I'm loving it, I like the the authors don't beat around the bush and just come straight out and say what the book is sopposed to be. They assume the you have computer experience. I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.