<%@ Language=VBScript %>
<%
Dim conn, strConn, strSQL, name, phone, goAhead
name=Request("txtCompanyName")
phone=Request("txtPhone")

For Each key In Request.Form
    If Request.Form(key) = "" Then
    If key = "txtCompanyName" Then
        Response.Write "<FONT Color = 'Blue'>Please enter the Shipper name.</Font>"
    Else
        Response.Write "<FONT Color = 'Red'>Please enter the Phone number.</Font>"
    End If
    goAhead = False
    Exit For
    End If
    GoAhead=True
Next
If goAhead = True Then
    name=Replace(Request("txtCompanyName"),"'","''")
        If Len(name)<> 0 Or _
                    Len(phone)<>0 Then
            Set conn = Server.CreateObject("ADODB.Connection")
            strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
            strConn=strConn & server.MapPath("Northwind.mdb") & ";"
            strConn=strConn & "User ID=; Password=;"

            strSQL = "INSERT INTO Shippers (CompanyName, phone)"
            strSQL = strSQL & "Values ('" & name & "'"
            strSQL = strSQL & ",'" & phone & "')"
            With conn
            .Mode = 3
            .Open strConn
            .Execute(strSQL)
        End With
        Response.Write "<I><FONT Color = 'Green'>" & _
                       "Successfully added the following data:</I></FONT><HR>"

         ' get the ShipperID (the autonumber field in the Shippers table)
         strSQL = "SELECT MAX(ShipperID) AS lastID From Shippers;"

         Set rst = conn.Execute(strSQL)
         Response.Write "Shipper ID: <B>" & rst("lastID")& "</B><P>"

         rst.close
         Set rst = Nothing
         conn.Close
         Set conn = Nothing

         Response.Write "Company Name: <B>" & Request("txtCompanyName") & _
                        "</B></P>"
         Response.Write "Phone Number: <B>" & phone & "</B>"

         ' clear the Shipper Name and Phone input boxes
         name = ""
         phone = ""
    End If
End If
%>
<HTML>
<HEAD>
<TITLE>Data Entry Screen</TITLE>
</HEAD>
<BODY>
<FORM Name="form1" Action="NWDataEntry.asp" Method="POST" >
    <P>
        Shipper Name: <INPUT Type="text" Name="txtCompanyName"
            Value="<%=name%>" Size= "30" >&nbsp;
        Phone: <INPUT Type="text" Name="txtPhone" Value="<%=phone%>"></P>
    <P>
<INPUT Type="Submit" Name="cmdSubmit" Value="Add Data"></P>
</FORM>
</BODY>
</HTML>