Print Page | Close Window

ASP add data to access question

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4799
Printed Date: 30 March 2026 at 2:51pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: ASP add data to access question
Posted By: eddyb
Subject: ASP add data to access question
Date Posted: 06 August 2003 at 7:50am

I have set up a access database which I want to add data to using ASP. I followed the tutorial at http://www.webwiz.net/asp/tutorials/add_to_database.asp - http://www.webwiz.net/asp/tutorials/add_to_database.asp  and it works fine.

The problem is that if you dont enter text into all of the fields then it crashes and doesn't work. How can I change it so it still works even if not all the fields are filled in?

I have a database which has about 60 fields and is 10mb with no records. Am I going to run into file size problems. About 120 records will be added to it using the asp form. (the form from the above tutorial)

Many Thanks,

Ed




Replies:
Posted By: PaulGQ
Date Posted: 07 August 2003 at 12:27pm

In access, just make sure the "required property" is net to no in each field.

That usually does it.

That amount of data is fine with access, buy at 50,000 records, I would then look into a sql server.

Also try to run it on a dual p3 machine or better with a gig or ram and a 15krpm hard drive.



Posted By: eddyb
Date Posted: 08 August 2003 at 1:44am

Hi,

Thanks, but the 'require property' is not in the script. Do I need to put it in then set it to no?

The code for the asp is:

<%
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim rsAddComments   'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb")

'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tbdata.name, tbdata.company, tbdata.date, tbdata.staff FROM tbdata;"

'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3

'Open the recordset with the SQL query
rsAddComments.Open strSQL, adoCon

'Tell the recordset we are adding a new record to it
rsAddComments.AddNew

'Add a new record to the recordset
rsAddComments.Fields("name") = Request.Form("name")
rsAddComments.Fields("company") = Request.Form("company")
rsAddComments.Fields("date") = Request.Form("date")
rsAddComments.Fields("staff") = Request.Form("staff")

'Write the updated recordset to the database
rsAddComments.Update

'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing

'Redirect to the guestbook.asp page
Response.Redirect "thanks.htm"
%>

Thanks,  Ed



Posted By: PaulGQ
Date Posted: 08 August 2003 at 1:47am

no, in the access database itself.

just code the script normally.  The error ison the access side, not the script side.  It is access that generates the eorror and passes it back to the browser.

 

Or you could lalways add code that adds a blank space to any firled that is empty.  But work on the access side, that is better.



Posted By: eddyb
Date Posted: 08 August 2003 at 1:57am

I checked the database and the required settings are already set to no. A copy of the form can be found at:

http://www.webwiz.net/asp/tutorials/guestbook/guestbook_form.htm - http://www.webwiz.net/asp/tutorials/guestbook/guestbook_form.htm

Note if you only fill in one feild it is not added to the database.

 

Cheers,

Ed



Posted By: PaulGQ
Date Posted: 08 August 2003 at 2:17am

here use this. 3 part form.  never do it all in one page.

first the form.asp pointing to the processor with this

<form action=formProcessor.asp>

 

now for formprocessor.asp - this is the whole thing

<%
Comments = Request.Form("Comments")
Name = Request.Form("Name")
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DBQ=" & Server.Mappath("Database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
SQLstmt = "INSERT INTO tblName (Comments, Name)values('" & Comments & "', '" & Name & "')"
Set RS = Conn.Execute(SQLStmt)
conn.Close
Set conn = Nothing
%>

<META HTTP-EQUIV=REFRESH CONTENT="0;URL=ThankYouPage.asp">

thats it, very simple.

 

make sure you write a thank you page or it will error out.

 

 

 



Posted By: PaulGQ
Date Posted: 08 August 2003 at 2:30am

also, let me know if you ever want those results posted in the database and mailed somewhere all in one stroke.

 

 



Posted By: eddyb
Date Posted: 08 August 2003 at 2:34am

I think I found the problem. I had the database set to not allow zero strings as a responce. I have changed this and am downloading my database now to make sure it all went in OK.

If this works, I will be using the orginal script. Is there any benefit changing to the one you suggested?

Also I would be interested in having the results mailed to me as you suggested. How is this achieved?




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net