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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if record exists before inserting

Status
Not open for further replies.

evillin

Technical User
Jan 2, 2004
20
GB
Hi all

I have 'inherited' a half finished training database web application created using Dreamweaver Ultradev and MS Access 2000.

I have a page that allows a user to book on a course - they log in first (they have a unique ID) and their details are picked up and passed to the booking form, where they add some details and submit to a table called 'CourseBooking'

At the moment it allows the user to book the same course multiple times as it doesnt check if the combination of traineeID and CourseID already exist in the 'CourseBooking' table.

I'm not used to using ultradev or MX - would normally code using classic ASP.

Very grateful if anyone can help with how to code a check before insertion?

The insert part looks as follows:

' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_training_STRING
MM_editTable = "CourseBooking"
MM_editRedirectUrl = "confirmbooking.asp"
MM_fieldsStr = "txtTraineeID|value|txtCourseID|value|txtPMExperience|value|txtCurrentProject|value|txtBenefits|value|txtGains|value"
MM_columnsStr = "TraineeId|none,none,NULL|CourseID|none,none,NULL|PMExperience|',none,''|CurrentProject|',none,''|Benefits|',none,''|Gains|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If

%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If

%>
<%
Dim rstCourse__MMColParam
rstCourse__MMColParam = "1"
if (Request.QueryString("CourseID") <> "") then rstCourse__MMColParam = Request.QueryString("CourseId")
%>

 
basically create a recordset at the start of the page only selecting in txtTrainee & txtCourseID then if a record exists redirect to another page else process the insert/update. So it should look something like this (untested)

[code<%
Dim rsExists
Dim rsExists_numRows

Set rsExists = Server.CreateObject("ADODB.Recordset")
rsExists.ActiveConnection = MM_training_STRING
rsExists.Source = "SELECT * FROM CourseBooking WHERE TRaineeId ='" & txtTraineeID & "' AND CourseID = '" & txtCourseID & "'"
rsExists.CursorType = 0
rsExists.CursorLocation = 2
rsExists.LockType = 1
rsExists.Open()

rsExists_numRows = 0
%>

<%
If rsExists.EOF And rsExists.BOF Then
%>


<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_training_STRING
MM_editTable = "CourseBooking"
MM_editRedirectUrl = "confirmbooking.asp"
MM_fieldsStr = "txtTraineeID|value|txtCourseID|value|txtPMExperience|value|txtCurrentProject|value|txtBenefits|value|txtGains|value"
MM_columnsStr = "TraineeId|none,none,NULL|CourseID|none,none,NULL|PMExperience|',none,''|CurrentProject|',none,''|Benefits|',none,''|Gains|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If

%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If

%>
<%
Dim rstCourse__MMColParam
rstCourse__MMColParam = "1"
if (Request.QueryString("CourseID") <> "") then rstCourse__MMColParam = Request.QueryString("CourseId")
%>
<% Else %>
Sorry you have already booked this course
<% End If ' end rsExists.EOF And rsExists.BOF %>[/code]

Cheech

[Peace][Pipe]
 
Many thanks for your quick reply - have been working on similar this morning. Tried your suggestion but getting error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

Relates to line 46 - the statement
"SELECT * FROM qryCourseAttendee WHERE TraineeId ='" & txtTraineeID & "' AND CourseID = '" & txtCourseID & "'"


Latest code below - again - thanks for your time - much appreciated...

' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>

<%
Dim rstTraineeAttendee
Dim rstTraineeAttendee_numRows
set rstTraineeAttendee = Server.CreateObject("ADODB.Recordset")
rstTraineeAttendee.ActiveConnection = MM_training_STRING
rstTraineeAttendee.Source = "SELECT * FROM qryCourseAttendee WHERE TraineeId ='" & txtTraineeID & "' AND CourseID = '" & txtCourseID & "'"
rstTraineeAttendee.CursorType = 0
rstTraineeAttendee.CursorLocation = 2
rstTraineeAttendee.LockType = 3
rstTraineeAttendee.Open()
rstTraineeAttendee_numRows = 0
%>
<%
If rstTraineeAttendee.EOF AND rstTraineeAttendee.BOF then
%>
<%


' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_training_STRING
MM_editTable = "tblAttendee"
MM_editRedirectUrl = "confirmbooking.asp"
MM_fieldsStr = "txtTraineeID|value|txtCourseID|value|txtPMExperience|value|txtCurrentProject|value|txtBenefits|value|txtGains|value"
MM_columnsStr = "TraineeId|none,none,NULL|CourseID|none,none,NULL|PMExperience|',none,''|CurrentProject|',none,''|Benefits|',none,''|Gains|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If

%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
err=false
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If

%>
<%
Dim rstCourse__MMColParam
rstCourse__MMColParam = "1"
if (Request.QueryString("CourseID") <> "") then rstCourse__MMColParam = Request.QueryString("CourseId")
%>
<%ELSE%> Sorry, you have already booked a place on this course.
<% End if 'end rstTraineeAttendee.EOF AND rstTraineeAttendee.BOF %>
<%
set rstCourse = Server.CreateObject("ADODB.Recordset")
rstCourse.ActiveConnection = MM_training_STRING
rstCourse.Source = "SELECT * FROM qryCourseDetails WHERE CourseID = " + Replace(rstCourse__MMColParam, "'", "''") + ""
rstCourse.CursorType = 0
rstCourse.CursorLocation = 2
rstCourse.LockType = 3
rstCourse.Open()
rstCourse_numRows = 0
%>

<%
Dim rstTrainee__MMColParam
rstTrainee__MMColParam = "1"
if (Session("TraineeID") <> "") then rstTrainee__MMColParam = Session("TraineeID")
%>
<%
set rstTrainee = Server.CreateObject("ADODB.Recordset")
rstTrainee.ActiveConnection = MM_training_STRING
rstTrainee.Source = "SELECT * FROM qryTrainee WHERE TraineeID = " + Replace(rstTrainee__MMColParam, "'", "''") + ""
rstTrainee.CursorType = 0
rstTrainee.CursorLocation = 2
rstTrainee.LockType = 3
rstTrainee.Open()
rstTrainee_numRows = 0
%>
<%
Dim rstCourseTimes__MMColParam
rstCourseTimes__MMColParam = "1"
if (Request.QueryString("CourseId") <> "") then rstCourseTimes__MMColParam = Request.QueryString("CourseId")
%>
<%
set rstCourseTimes = Server.CreateObject("ADODB.Recordset")
rstCourseTimes.ActiveConnection = MM_training_STRING
rstCourseTimes.Source = "SELECT * FROM qryCourseTimes WHERE CourseId = " + Replace(rstCourseTimes__MMColParam, "'", "''") + ""
rstCourseTimes.CursorType = 0
rstCourseTimes.CursorLocation = 2
rstCourseTimes.LockType = 3
rstCourseTimes.Open()
rstCourseTimes_numRows = 0
%>

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
function DoDateTime(str, nNamedFormat, nLCID)
dim strRet
dim nOldLCID

strRet = str
If (nLCID > -1) Then
oldLCID = Session.LCID
End If

On Error Resume Next

If (nLCID > -1) Then
Session.LCID = nLCID
End If

If ((nLCID < 0) Or (Session.LCID = nLCID)) Then
strRet = FormatDateTime(str, nNamedFormat)
End If

If (nLCID > -1) Then
Session.LCID = oldLCID
End If

DoDateTime = strRet
End Function
</SCRIPT>
<%
rstCourse.Close()
%>
<%
rstTrainee.Close()
%>
<%
rstCourseTimes.Close()
%>

 
where do you gt the 2 variables from. They are not defined in that code

Cheech

[Peace][Pipe]
 
On the same page further down is ...

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="frmCourse">

<%
Dim varCourseId, varTraineeID
varCourseID = Request.QueryString("CourseID")
varTraineeID = Session("TraineeID")
%>

<input type="hidden" name="txtTraineeID" value="<%=varTraineeID%>">

<input type="hidden" name="txtCourseID" value="<%=varCourseID%>">
 
Move this to the top of the page and then change the select statement
Code:
<% 
Dim varCourseId, varTraineeID
varCourseID = Request.QueryString("CourseID")
varTraineeID = Session("TraineeID")
%>
"SELECT * FROM qryCourseAttendee WHERE TraineeId ='" & varTraineeID & "' AND CourseID = '" & varCourseID & "'"

Hopefully that will sort you out

Cheech


[Peace][Pipe]
 
Many thanks for your time here. Have tried as suggested but still the error

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

AAarrrggghhh. If anyone can help, much appreciated - is driving me mad :)

My code as it is now...
Code:
<%@LANGUAGE="VBSCRIPT"%> 
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="gettrainee.asp?ctype=Book&CourseID=" & Request.QueryString("CourseID")
MM_grantAccess=false
If Session("TraineeID") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<!--#include file="include.asp" -->
<% 
Dim varCourseId, varTraineeID, rstCourseAttendee
varCourseID = Request.QueryString("CourseID")
varTraineeID = Session("TraineeId")
%>
<%
set rstCourseAttendee = Server.CreateObject("ADODB.Recordset")
rstCourseAttendee.ActiveConnection = MM_training_STRING
rstCourseAttendee.Source = "SELECT * FROM tblAttendee WHERE TraineeId = '" &varTraineeID& "' AND CourseID = '" & varCourseID& "'"
rstCourseAttendee.CursorType = 0
rstCourseAttendee.CursorLocation = 2
rstCourseAttendee.LockType = 3
rstCourseAttendee.Open()
rstCourseAttendee_numRows = 0
%>
<%
If rstCourseAttendee.EOF and rstCourseAttendee.BOF then
%>

<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

  MM_editConnection = MM_training_STRING
  MM_editTable = "tblAttendee"
  MM_editRedirectUrl = "confirmbooking.asp"
  MM_fieldsStr  = "txtTraineeID|value|txtCourseID|value|txtPMExperience|value|txtCurrentProject|value|txtBenefits|value|txtStartDate|value|txtEndDate|value|txtGains|value"
  MM_columnsStr = "TraineeId|none,none,NULL|CourseID|none,none,NULL|PMExperience|',none,''|CurrentProject|',none,''|Benefits|',none,''|TargetStart|#,none,NULL|TargetEnd|#,none,NULL|Gains|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
  
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim rstCourse__MMColParam
rstCourse__MMColParam = "1"
if (Request.QueryString("CourseID") <> "") then rstCourse__MMColParam = Request.QueryString("CourseId")
%>

<%
set rstCourse = Server.CreateObject("ADODB.Recordset")
rstCourse.ActiveConnection = MM_training_STRING
rstCourse.Source = "SELECT * FROM qryCourseDetails WHERE CourseID = " + Replace(rstCourse__MMColParam, "'", "''") + ""
rstCourse.CursorType = 0
rstCourse.CursorLocation = 2
rstCourse.LockType = 3
rstCourse.Open()
rstCourse_numRows = 0
%>
<%
Dim rstTrainee__MMColParam
rstTrainee__MMColParam = "1"
if (Session("TraineeID") <> "") then rstTrainee__MMColParam = Session("TraineeID")
%>
<%
set rstTrainee = Server.CreateObject("ADODB.Recordset")
rstTrainee.ActiveConnection = MM_training_STRING
rstTrainee.Source = "SELECT * FROM qryTrainee WHERE TraineeID = " + Replace(rstTrainee__MMColParam, "'", "''") + ""
rstTrainee.CursorType = 0
rstTrainee.CursorLocation = 2
rstTrainee.LockType = 3
rstTrainee.Open()
rstTrainee_numRows = 0
%>



<%
Dim rstCourseTimes__MMColParam
rstCourseTimes__MMColParam = "1"
if (Request.QueryString("CourseId") <> "") then rstCourseTimes__MMColParam = Request.QueryString("CourseId")
%>

<%
set rstCourseTimes = Server.CreateObject("ADODB.Recordset")
rstCourseTimes.ActiveConnection = MM_training_STRING
rstCourseTimes.Source = "SELECT * FROM qryCourseTimes WHERE CourseId = " + Replace(rstCourseTimes__MMColParam, "'", "''") + ""
rstCourseTimes.CursorType = 0
rstCourseTimes.CursorLocation = 2
rstCourseTimes.LockType = 3
rstCourseTimes.Open()
rstCourseTimes_numRows = 0
%>
<%ELSE%>
You have already booked a place on this course.
<% End if 'end rstattendee EOF and BOF %>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>					
function DoDateTime(str, nNamedFormat, nLCID)				
	dim strRet								
	dim nOldLCID								
										
	strRet = str								
	If (nLCID > -1) Then							
		oldLCID = Session.LCID						
	End If									
										
	On Error Resume Next							
										
	If (nLCID > -1) Then							
		Session.LCID = nLCID						
	End If									
										
	If ((nLCID < 0) Or (Session.LCID = nLCID)) Then				
		strRet = FormatDateTime(str, nNamedFormat)			
	End If									
										
	If (nLCID > -1) Then							
		Session.LCID = oldLCID						
	End If									
										
	DoDateTime = strRet							
End Function									
</SCRIPT>
<html>
<head>
<title>Book Course</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/style.css" type="text/css">
<link rel="stylesheet" href="../css/training.css" type="text/css">
<meta name="Microsoft Border" content="tlb, default">
</head>
<body onload="javascript:document.frmCourse.txtPMExperience.focus()"><!--msnavigation-->

   
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="frmCourse">

         <input type="hidden" name="txtTraineeID" value="<%=varTraineeID%>"> 
              <input type="hidden" name="txtCourseID" value="<%=varCourseID%>">
              Course:
       <%=(rstCourse.Fields.Item("Title").Value)%>
         
            Duration:
            <%=(rstCourse.Fields.Item("DaysDuration").Value)%> 
              day(s)
          
            Date Time of 
              Course: 
            
              <% 
While (NOT rstCourseTimes.EOF) 
%>
              <%= DoDateTime((rstCourseTimes.Fields.Item("Date").Value), 2, 2057) %>&nbsp;(<%=DoDateTime((rstCourseTimes.Fields.Item("Start").Value),4,1033)%>-<%=DoDateTime((rstCourseTimes.Fields.Item("End").Value),4,1033)%>)<br> 
              <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rstCourseTimes.MoveNext()
Wend
%>
                
        
          <input type="submit" name="btnSubmit" value="Submit"> 
              <input type="reset" name="btnReset" value="Reset"> 
  <input type="hidden" name="MM_insert" value="true">
</form>


</body>
</html>
<%
rstCourse.Close()
%>
<%
rstTrainee.Close()
%>
<%
rstCourseTimes.Close()
%>
<%
rstCourseAttendee.Close()
%>
 
woops - have corrected the code below but now have errorMicrosoft VBScript compilation (0x800A0409)
Unterminated string constant

At line MM_editTable = "tblAttendee"

Code:
 MM_fieldsStr  = "txtTraineeID|value|txtCourseID|value|txtPMExperience|value|txtCurrentProject|value|txtBenefits|value|
  |txtGains|value"
  MM_columnsStr = "TraineeId|none,none,NULL|CourseID|none,none,NULL|PMExperience|',none,''|CurrentProject|',none,''|Benefits|',none,''|Gains|',none,''"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top