Re: Addnew method failed on empty recordset



Max wrote:
Hi i am having table Data with field name code, Data Table is empty,
when i tried to Addnew, Update method through ADO it fails it is not
showing any records ?

my syntex is

dim i as integer
cn.open path
rs.open "Data",cn,adOpenDynamic, adLockBatchOptimistic

thanx
for i=1 to 100
rs.addnew
rs!code= i
next

adOpenDynamic and adLockBatchOptimistic are mutually exclusive. You must
also have "on error resume next" somewhere because that open statement
should be throwing an error. You did not specify adCmtTable and "Data"
does not contain any sql keywords, so an error should have been raised.

Instead of using a recordset, do this instead:

dim i as integer
dim cmd as adodb.command
dim sql as string
sql = "insert into Data ([code]) values (?)"
cn.open path
set cmd = new adodb.command
with cmd
.commandtext = sql
.commandtype = adCmdText
set .activeconnection = cn
end with

for i=1 to 100
cmd.execute ,array(i),adExecuteNoRecords
next i
cn.close

If you must use a recordset for some reason, I need to question why you
are trying to use adLockBatchOptimistic - are you desiring to disconnect
the recordset?

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


.



Relevant Pages

  • Re: Saving rtf to SQL Column
    ... Dim cn As ADODB.Connection ... Dim Sql As String ... ' and use the stream code to stuff a text or ... Now all I get is an error saying the recordset does not support updating. ...
    (microsoft.public.vb.database.ado)
  • Re: SQL Update Issue
    ... If you want to drop the SQL, here is the sample using recordset method. ... Dim con As New ADODB.Connection ...
    (microsoft.public.access.formscoding)
  • Passing Query Parameters from form to another VBA subroutine
    ... but I was already using references to ... posted the SQL, but it's frikkin humongous). ... It said that when creating a recordset from ... Dim qdf As DAO.QueryDef ...
    (microsoft.public.access.queries)
  • Re: Median Calculation
    ... ?Median869("SELECT NumberSold As Qty, Price As Val FROM DavesTable ORDER ... Public Function Median869(ByVal SQL As String) As Variant ... Dim rst As DAO.Recordset ... MsgBox "Empty recordset", vbExclamation + vbOKOnly ...
    (microsoft.public.access.modulesdaovba)
  • Re: Statistische Auswertung mit Access 2003
    ... > Dim R As Recordset ... Es gibt innerhalb von SQL eine Möglichkeit, SQL zählen zu lassen, ohne dies ... gibt dir ein Recordset mit einem Feld und dem ... End Function ...
    (microsoft.public.de.access)