Error msg when adding reocrds

From: Gman (Gman_at_discussions.microsoft.com)
Date: 02/05/05


Date: Sat, 5 Feb 2005 15:45:01 -0800

I am attempting to add records to a table using the code below. I get a type
mismtch error using DAO and an Object variable not assigned error using ADO.
eventually I will be taking data from a form and adding it to an added
records log table. I tookthe code directly from the reference books, But Im
stuck on the basics somewhere . Any Ideas? Thank you

DAO code
Sub AutoEnterStudents()
Dim CurDB As Database
Dim MyRecordSet As Recordset

Set CurDB = CurrentDb
Set MyRecordSet = CurDB.OpenRecordset("tblStudents")' This is where I get
the error

With MyRecordSet
    .AddNew
    !LName = "Scott"
    .Update
End With

MyRecordSet.Close
End Sub

ADO Code
Sub AutoEdit2()

Dim CurConn As ADODB.Connection
Dim MyTable As ADODB.Recordset

Set CurConn = CurrentProject.Connection
' This is where I get the error

            
MyTable.CursorType = adOpenKeyset
MyTable.LockType = adLockOptimistic
MyTable.Open "tblStudents", CurConn, , , adCmdTable

With MyTable
    .AddNew
    !LName = "Scott"
    .Update
End With

MyTable.Close
Set MyTable = Nothing
CurConn.Close
Set CurConn = Nothing



Relevant Pages

  • Re: Member or Data Member not Found
    ... Microsoft introduced a new data access method in the late 90s known as ADO. ... Access 97 and previous only had DAO in them. ... You must disambiguate as Dim rst As DAO.Recordset. ...
    (microsoft.public.access.formscoding)
  • Re: Need help with a DAO to ADO conversion
    ... the open/close code of the DAO object. ... Dim wksCurr As DAO.Workspace ... Dim fldCurr As DAO.Field ... Set dbCurr = OpenDatabase ...
    (microsoft.public.access.formscoding)
  • Re: Refreshing subform
    ... the new data is added to the subform. ... I do not want to use DAO. ... >> Dim CurrConn As New ADODB.Connection ... >> Exit Sub ...
    (microsoft.public.access.formscoding)
  • Re: Address List
    ... DAO, so the lines that Duane has for ADO need to be commented out and the ... Dim rs As DAO.Recordset ... Dim strConcat As String 'build return string ... "John Spencer" wrote: ...
    (microsoft.public.access.queries)
  • Re: Moving ADO routine back to DAO
    ... Problems with missing DAO 3.6 references are not unheard of, ... non-trivial app, though. ... > I have a client running an app I developed ... > 110: Dim errloop As Error ...
    (microsoft.public.access.modulesdaovba)