Using RecordSets within Access 2000 Data Access Pages 
Author Message
 Using RecordSets within Access 2000 Data Access Pages

I have an Access 2000 Data Access Page, on which I want to delete and create
Database Records.

I am using VB Script to perform validation on the form, and in this script I
want to create & delete Database Records.  In Access I would normally use
something like:\

        RecordSet.Addnew

        RecordSet.Update

How do I do this in VB Scripts?

Thanks for any help.

Andrew



Wed, 20 Feb 2002 03:00:00 GMT  
 Using RecordSets within Access 2000 Data Access Pages
Why are you using 3 objects (a command, recordset and connection), when only
one (a connection) is needed?

<%
strSQL= "INSERT INTO gpDocument FIELDS" & _
"(GroupCode,FolderID,DocName,ObjectName) " & _
"Values" & _
"(''511','FolderLink','" & DocSyFile.Form("name") & "','savename')"

Set DocSys_Conn = Server.CreateObject("ADODB.Connection")
DocSys_Conn.ConnectionTimeout = Session("DocSys_ConnectionTimeout")
DocSys_Conn.Open Session("DocSys_ConnectionString"),
Session("DocSys_RuntimeUserName"), Session("DocSys_RuntimePassword")

DocSys_Conn.Execute strSQL

DocSys_Conn.Close
%>

??

Only a fraction of the code and a single object instead of 3 (which
conserves server resources). What are you gaining by opening a command and
recordset object here?

Furthermore, I've often seen the use of two objects (recordset and
connection) to do an AddNew, but why add a command object, too? Even an
AddNew with just a recordset and connection would take less code and use
fewer server resources.

Kurt


Quote:
> The same way.  Below is part of a code (on ASP using VBScript):

> REM Set database connection and open recordset
> Set DocSys_Conn = Server.CreateObject("ADODB.Connection")
> DocSys_Conn.ConnectionTimeout = Session("DocSys_ConnectionTimeout")
> DocSys_Conn.CommandTimeout = Session("DocSys_CommandTimeout")
> DocSys_Conn.Open Session("DocSys_ConnectionString"),
> Session("DocSys_RuntimeUserName"), Session("DocSys_RuntimePassword")
> Set cmd = Server.CreateObject("ADODB.Command")
> Set Data = Server.CreateObject("ADODB.Recordset")
> cmd.CommandText = "gpDocument"
> cmd.CommandType = adCmdTable
> Data.CursorType = adOpenKeyset
> Data.LockType = adLockOptimistic
> Set cmd.ActiveConnection = DocSys_Conn
> Data.Open cmd

> REM Insert a new record
> Data.AddNew

> REM Assign values to columns of newly created record
> Data("GroupCode") = "511"
> Data("FolderID") = FolderLink
> Data("DocName") = DocSysFile.Form("name")
> Data("ObjectName") = savename

> REM Save values
> Data.Update

> REM Close connection
> Data.Close
> DocSys_Conn.Close
> Set Data = Nothing
> Set cmd = Nothing
> Set DocSys_Conn = Nothing

> The above code works on Access 97 and 2000 and SQL Server 6.5 and 7.0
> (probably on all databases).

> Hope this helps.



> > I have an Access 2000 Data Access Page, on which I want to delete and
> create
> > Database Records.

> > I am using VB Script to perform validation on the form, and in this
script
> I
> > want to create & delete Database Records.  In Access I would normally
use
> > something like:\

> >         RecordSet.Addnew

> >         RecordSet.Update

> > How do I do this in VB Scripts?

> > Thanks for any help.

> > Andrew



Wed, 20 Feb 2002 03:00:00 GMT  
 Using RecordSets within Access 2000 Data Access Pages
The same way.  Below is part of a code (on ASP using VBScript):

REM Set database connection and open recordset
Set DocSys_Conn = Server.CreateObject("ADODB.Connection")
DocSys_Conn.ConnectionTimeout = Session("DocSys_ConnectionTimeout")
DocSys_Conn.CommandTimeout = Session("DocSys_CommandTimeout")
DocSys_Conn.Open Session("DocSys_ConnectionString"),
Session("DocSys_RuntimeUserName"), Session("DocSys_RuntimePassword")
Set cmd = Server.CreateObject("ADODB.Command")
Set Data = Server.CreateObject("ADODB.Recordset")
cmd.CommandText = "gpDocument"
cmd.CommandType = adCmdTable
Data.CursorType = adOpenKeyset
Data.LockType = adLockOptimistic
Set cmd.ActiveConnection = DocSys_Conn
Data.Open cmd

REM Insert a new record
Data.AddNew

REM Assign values to columns of newly created record
Data("GroupCode") = "511"
Data("FolderID") = FolderLink
Data("DocName") = DocSysFile.Form("name")
Data("ObjectName") = savename

REM Save values
Data.Update

REM Close connection
Data.Close
DocSys_Conn.Close
Set Data = Nothing
Set cmd = Nothing
Set DocSys_Conn = Nothing

The above code works on Access 97 and 2000 and SQL Server 6.5 and 7.0
(probably on all databases).

Hope this helps.


Quote:
> I have an Access 2000 Data Access Page, on which I want to delete and
create
> Database Records.

> I am using VB Script to perform validation on the form, and in this script
I
> want to create & delete Database Records.  In Access I would normally use
> something like:\

>         RecordSet.Addnew

>         RecordSet.Update

> How do I do this in VB Scripts?

> Thanks for any help.

> Andrew



Thu, 21 Feb 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Automating email function within Word 2000 using Access 2000

2. saving data from a VB form to access 2000 or excel 2000

3. Transfer Record within Access 2000 Tables using VB6 Sql

4. Transfer tables within Access 2000 Record using VB6

5. Transfer Record within Access 2000 Tables using VB6 Sql

6. Transfer tables within Access 2000 Record using VB6

7. change printer from within a VB module within Access 2000

8. data pages access 2000

9. Recordset search of an Access 2000 database

10. Access 2000 converted to Access 97 report query data type errors

11. Linking Access 97 fornt end to Access 2000 data

12. Importing data using Access 2000 and SQL 7

 

 
Powered by phpBB® Forum Software