SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating MS Access database by clicking a button in an ASP page

    Hi,

    I am trying to update a MS Access database record, when an user clicks on a button in an ASP page.
    Problem is - there are two buttons and ASP code related to both the buttons get executed when I click the button. I want that - sub related to the button should only be called when user clicks the button. Here is the code:

    <%
    Sub butEstopClick
    Dim oConn Dim oRs
    Dim filePath
    filePath = Server.MapPath("test.mdb")
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath

    'Input_to_VB is a table name and Estop is field name
    oConn.Execute "Update Input_to_VB Set Estop ='Yes'" _
    & "where Estop='No' "
    oConn.Close

    End Sub


    Sub butResetClick()
    Dim oConn
    Dim oRs
    Dim filePath
    filePath = Server.MapPath("test.mdb")
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath

    'Input_to_VB is a table name and Reset is field name
    oConn.Execute "Update Input_to_VB Set Reset ='Yes'" _
    & "where Reset ='No' "
    oConn.Close
    End Sub
    %>

    <INPUT type="button" value="ESTOP" id=butEstop name=butEstop onclick="<%butEstopClick%>" style="BACKGROUND-COLOR: red">

    <INPUT type="button" value="RESET" id=butReset name=butReset onclick="<%butResetClick%>">

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not use two forms? Put in a querystring or a hidden field check in your form so when it is processed it will only execute the correct function.
    Code:
    <%
    if request.form("check") = "estop" then
    
       Dim oConn Dim oRs 
       Dim filePath 
       filePath = Server.MapPath("test.mdb") 
       Set oConn = Server.CreateObject("ADODB.Connection") 
       oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath 
    
       'Input_to_VB is a table name and Estop is field name 
       oConn.Execute "Update Input_to_VB Set Estop ='Yes'" _ 
       & "where Estop='No' " 
       oConn.Close 
    
    else if request.form("check") = "reset" then
    
       Dim oConn 
       Dim oRs 
       Dim filePath 
       filePath = Server.MapPath("test.mdb") 
       Set oConn = Server.CreateObject("ADODB.Connection") 
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath 
    
       'Input_to_VB is a table name and Reset is field name 
       oConn.Execute "Update Input_to_VB Set Reset ='Yes'" _ 
        & "where Reset ='No' " 
       oConn.Close 
    
    else
    
       response.write ("Invalid input")
    
    end if
    end if
    %>
    
    
    
    <form action="self.asp" method="post">
    <input type="hidden" name="check" value="estop">
    <input type="submit" value="Estop">
    </form>
    
    <form action="self.asp" method="post">
    <input type="hidden" name="check" value="reset">
    <input type="submit" value="Reset">
    </form>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •