Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2004, 02:49 PM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding value to drop down list

Ok I have another scenario now it's a bit hard to explain but I will try my best. I am trying to add an estimate number to an existing contract number but it tells me the estimate number already exists. Obviously because let's say contract number S-888 has 10 estimates and contract number S-444 has 5 estimates. But my problem is how can I add an estimate number without giving me the duplicate error? Any help please would truly help thanks :). Here are the functions:

<%

' --- FUNCTIONS STARTS BELOW

Function searchContract()

    ' Local Recordset
    dim rsLocal
    set rsLocal = server.CreateObject("adodb.recordset")
    ' Search for a contract alone or contract AND estimate
    if strEstimateNum <> "" then
        ' Set rsLocal = FindEstimateContracts(strContractNum, strEstimateNum)
        SQL = "Select * from tblEstimates(nolock) where contno = '" & strContractNum & "' and estno='" & strEstimateNum & "' order by estno"
    else
        SQL = "Select top 1 * from tblEstimates(nolock) where contno = '" & strContractNum & "' order by estno"
    end if
    ' Open Recordset
    rsLocal.Open SQL, cn

    ' Check for end of file (eof)
    if rsLocal.EOF then
      'response.write "<script language=javascript>alert('Project Number Not Found');</script>"
      %>
        <script language=javascript>
            alert("Contract Number Not Found");
        </script>
      <%
    else
      do while not rsLocal.EOF
        contno = rsLocal("contno")
        estno = rsLocal("estno")
        contractor = rsLocal("contractor")
        estamt = iif(isnull(rsLocal("estamt")), 0, rsLocal("estamt"))
        retainage=iif(isnull(rsLocal("retainage")), 0, rsLocal("retainage"))
        otherdeduct=iif(isnull(rsLocal("otherdeduct")),0, rsLocal("otherdeduct"))
        netestamt=iif(isnull(rsLocal("netestamt")), 0, rsLocal("netestamt"))
        amttodate=iif(isnull(rsLocal("amttodate")),0, rsLocal ("amttodate"))
        rsvdcontamt=iif(isnull(rsLocal("rsvdcontamt")),0, rsLocal("rsvdcontamt"))
        estdate=rsLocal("estdate")
        perenddate=rsLocal("perenddate")
        eststatus=rsLocal("eststatus")
        prelimrsvd=rsLocal("prelimrsvd")
        projmgrapproval=rsLocal("projmgrapproval")
        contractorsigned=rsLocal("contractorsigned")
        assistdirector=rsLocal("assistdirector")
        cmdchief=rsLocal("cmdchief")
        staffdone=rsLocal("staffdone")
        contreviewapproval=rsLocal("contreviewapproval")
        receiveddate=rsLocal("receiveddate")
        submittoap=rsLocal("submittoap")
        checkdate=rsLocal("checkdate")
        checkno=rsLocal("checkno")
        recfromap=rsLocal("recfromap")
        comments=rsLocal("comments")
        paiddate=rsLocal("paiddate")
        trackingnum=rsLocal("trackingnum")
      rsLocal.movenext
      loop
    end if

    set rsLocal = nothing
End Function

Function addContract()
    ' Local Recordset
    dim rsLocal
    ' Add Project
    set rsLocal = server.CreateObject("adodb.recordset")
    SQL = "select * from tblEstimates where estno = '" & strEstimateNum & "'"
    'response.write "We are adding"
    'response.end
    ' Run Query
    rsLocal.open SQL, cn, 0, 3
    ' Check to see if project exists
    If not rsLocal.eof Then
        ' Estimate does not exist, add new record
        With rsLocal
            .addnew
            .Fields("estno") = strEstimateNum
            .update
            .close
        End With
    Else
        ' Project already exists, display error message
        Response.Write "Error: Estimate Number " & strEstimateNum & " already exists!"
    End If
    set rsLocal = nothing
End Function

Function updateContract()
    ' Local Recordset
    dim rsLocal
    ' Update Contract
    set rsLocal = server.CreateObject("adodb.recordset")
    SQL = "select * from tblEstimates where estno = '" & strEstimateNum & "'"
    'response.write "We are updating " & SQL
    With rsLocal
        .open SQL, cn, 0, 3
        If .recordcount = 1 then
            '.Fields("contno") = request("contno") <- never update key fields
            .Fields("estno") = request("estno")
            .Fields("contractor") = request("contractor")
            .Fields("estamt") = request("estamt")
            .Fields("retainage") = request("retainage")
            .Fields("otherdeduct") = request("otherdeduct")
            .Fields("netestamt") = request("netestamt")
            .Fields("amttodate") = request("amttodate")
            .Fields("rsvdcontamt")=request("rsvdcontamt")
            .Fields("estdate")=convertBlankToNull(request("est date"))
            .Fields("perenddate")=convertBlankToNull(request(" perenddate"))
            .Fields("eststatus")=request("eststatus")
            .Fields("prelimrsvd")=convertBlankToNull(request(" prelimrsvd"))
            .Fields("projmgrapproval") = convertBlankToNull(request("projmgrapproval"))
            .Fields("contractorsigned") = convertBlankToNull(request("contractorsigned"))
            .Fields("assistdirector") = convertBlankToNull(request("assistdirector"))
            .Fields("cmdchief") = convertBlankToNull(request("cmdchief"))
            .Fields("staffdone") = convertBlankToNull(request("staffdone"))
            .Fields("contreviewapproval")=convertBlankToNull(r equest("contreviewapproval"))
            .Fields("receiveddate")=convertBlankToNull(request ("receiveddate"))
            .Fields("submittoap")=convertBlankToNull(request(" submittoap"))
            .Fields("checkdate")=convertBlankToNull(request("c heckdate"))
            .Fields("checkno")=convertBlankToNull(request("che ckno"))
            .Fields("recfromap")=convertBlankToNull(request("r ecfromap"))
            .Fields("comments")=request("comments")
            .Fields("paiddate")=convertBlanktoNull(request("pa iddate"))
            .Fields("trackingnum")=request("trackingnum")
            .update
            .close
            '.movelast
        Else
            response.write "Error: Attempting to update " & .recordcount &" records is not allowed. Please contact system administrator."
        End If
    End With
    set rsLocal = nothing

End Function

Function deleteContract()
    ' Local Recordset
    dim rsLocal
    ' Delete Contract
    Set rsLocal = server.CreateObject("adodb.recordset")
    SQL = "select * from tblEstimates where estno = '" & strEstimateNum & "'"
    'response.write "We are deleting"
    'response.end
    ' Run Query
    rsLocal.open SQL, cn, 0, 3
    ' Check to see if project exists
    If not rsLocal.eof Then
        ' deletes record
        With rsLocal
            .delete
            .movenext
            .close
        End With
    Else
        ' Contract does not exists, display error message
        ' Response.Write "Error: Contract " & strContractNum & " no longer exists!"
    End If
    set rsLocal = nothing
End Function

' --- PROCESSING LOGIC STARTS BELOW

dim strContractNum, strEstimateNum, rsContr, contno, estno, contractor, estamt, retainage, otherdeduct, netestamt, amttodate, rsvdcontamt, estdate, perenddate, eststatus, prelimrsvd, projmgrapproval, contractorsigned, assistdirector, cmdchief, staffdone, contreviewapproval, receiveddate, submittoap, checkdate, checkno, recfromap, comments, paiddate, trackingnum, btnAction

' check if we are searching for a contract
strContractNum = request("contractnumhidden") ' from hidden variable
' check if we are searching for an estimate number
strEstimateNum = request("estimatenumhidden") ' from hidden variable

' Process the Add/Update/Delete/Search functions
btnAction = request("btnAction")
select case btnAction
    case "AddEstimate"
        ' Add the contract
        if strEstimateNum <> "" then ' Make sure user entered a value
            addContract()
            response.write "in add function add estimate " & strEstimateNum
            'response.end
            ' After the add, perform a search to reload contract :)
            searchContract
        end if
    case "UpdateEstimate"
        ' Update the estimate
        if strEstimateNum <> "" then
            updateContract()
            response.write "in update function update estimate " & strEstimateNum
            response.end
            ' After the update, perform a search to reload contract :)
            searchContract
        end if
    case "DeleteEstimate"
        'Delete the estimate
        if strEstimateNum <> "" then
            deleteContract()
            response.write "in delete function delete estimate " & strEstimateNum
            response.end
            ' After the delete, perform a search to reload contract :)
            'searchContract
        end if
    case ""
        ' Process the search
        if strEstimateNum <> "" then
            searchContract
        end if
   end select
%>



slypunk
__________________
slypunk





Similar Threads
Thread Thread Starter Forum Replies Last Post
adding values from drop down menus racey Classic ASP Basics 1 August 22nd, 2006 05:26 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Drop Down List mrideout BOOK: Beginning ASP.NET 1.0 6 March 18th, 2005 03:32 AM
Drop Down List Beginner123 VB How-To 2 March 7th, 2005 01:56 PM
Drop Down List mrideout BOOK: Beginning ASP.NET 1.0 8 September 16th, 2004 07:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.