Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Feb 2009
    Location
    Seattle, WA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay - I have the code below - that's not working for me... My security policies on my work computer won't allow me to turn off the Friendly Error Blocking - so I'm stuck trying to debug the code visually - and I can't figure out why it won't work....

    If I had to guess - I'd say it has something to do w/ the fact that several of the form entries allow for multiple values - but I can't figure out what to do about it...

    Any ideas (or glaring inconsistencies) loungers?
    Thanks in advance,
    Dan

    Code:
    DIM objConn 'Holds the Database Connection Object
    Dim rsAddHoax 'Holds the recordset for the new record to be added
    Dim strSQL    'Holds the SQL query to query the database
    
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("hoax.mdb")
    
    Set rsAddHoax = Server.CreateObject("ADODB.Recordset")
    
    strSQL = "SELECT * FROM HoaxDB;"
    
    rsAddHoax.CursorType = 2
    
    rsAddHoax.LockType = 3
    
    rsAddHoax.Open strSQL, objConn
    
    rsAddHoax.AddNew
    
    'Add a new record to the recordset
    rsAddHoax.Fields("Unit") = Request.Form("Unit")
    rsAddHoax.Fields("dbSRC") = Request.Form("frmSRC")
    rsAddHoax.Fields("dbChar") = Request.Form("frmChar")
    rsAddHoax.Fields("Gender") = Request.Form("gender")
    rsAddHoax.Fields("Speed") = Request.Form("Speed")
    rsAddHoax.Fields("Age") = Request.Form("Age")
    rsAddHoax.Fields("Accent") = Request.Form("Accent")
    rsAddHoax.Fields("Strength") = Request.Form("Strength")
    rsAddHoax.Fields("Volume") = Request.Form("Volume")
    rsAddHoax.Fields("Pitch") = Request.Form("Pitch")
    rsAddHoax.Fields("Emphasis1") = Request.Form("emphasis1")
    rsAddHoax.Fields("Pronoun1") = Request.Form("pronoun1")
    rsAddHoax.Fields("Hoax") = Request.Form("Hoax")
    rsAddHoax.Fields("Shoreside") = Request.Form("shoreside")
    rsAddHoax.Fields("MISLE") = Request.Form("Misle")
    rsAddHoax.Fields("UCN") = Request.Form("UCN")
    rsAddHoax.Fields("Filename") = Request.Form("timestamp")
    'Write the updated recordset to the database
    rsAddHoax.Update
    
    
    'Reset server objects
    
    rsAddHoax.Close
    Set rsAddHoax = Nothing
    Set objConn = Nothing

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Are you saying that it works when you fill out the form with single values, or it just never works?

    First, I would try changing the right side of each field assignment to a suitable constant and see whether the record will add. If that works, great. If that doesn't work, there may be a problem with your recordset. When I had to add to an Access MDB from ASP, I opened the recordset on a table rather than using a query, as follows:

    Code:
    ' Do the Access database update
    Dim objConnA, strConnectA, objRSA
    ' Set up connection object and OLEDB string for local Access database
    Set objConnA = Server.CreateObject("ADODB.Connection")
    strConnectA = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    				"Data Source=" & Server.MapPath("folder/file.mdb")
    ' Open the connection
    objConnA.Open strConnectA
    ' Set up recordset and run query
    Set objRSA = Server.CreateObject("ADODB.Recordset")
    objRSA.Open "MyTable", objConnA, adOpenKeySet, adLockOptimistic, adCmdTable
    
    If objRSA.EOF Then
    	objConnA.Close
    	Response.Write "Unexpected EOF!" & vbCrLf & "Please contact Jefferson."
    Else
    	' Add new record to the recordset
    	objRSA.AddNew
    	' Populate fields with form data and other stuff
    	objRSA("Field1") 	= Request("Form1")
    	objRSA("Field2") = Request("Form2")
    	' etc.
    	objRSA("TimeAdded") = Now
    	If Trim(Request.ServerVariables("REMOTE_HOST")) <> "" Then
    		objRSA("UserIP") = Request.ServerVariables("REMOTE_HOST")
    	Else
    		objRSA("UserIP") = Request.ServerVariables("REMOTE_ADDR")
    	End If
    	' Save new record, close down database objects
    	objRSA.Update
    	objRSA.Close
    	objConnA.Close
    End If
    ' Clean Up	
    Set objRSA = Nothing
    Set objCommandA = Nothing
    Set objConnA = Nothing
    If that's an option for you, see whether that makes any difference.

    Second, I would try commenting out all fields/columns that are not mandatory and see whether the record will add. If so, one of the other fields has a problem. Perhaps that's too obvious.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I can't see anything obviously wrong.

    Two things you could try:
    • Can you read data from the table- try just selecting a record or two and writing the results out.
    • Write out the form contents back to the screen.
    Are you working on a Vista computer? On my Vista machine I could never get ASP pages to successfully connect to an Access database. Things that worked for years under XP, I could not get to work. I don't try to do it very often. Last time I had do all my testing on the web server rather than my own computer. There is lots of advice about how to fix the problem, but none of it worked for me.

    e.g.This knowledgebase article
    Regards
    John



Posting Permissions

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