Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Access 2000 code to Add record to a table. Have working 97 code.

Status
Not open for further replies.

Cybernetic2002

Programmer
Nov 20, 2001
7
CA
The following is code I used in a previous Access 97 app to add a new record to a table. When I put this code into my Access 2000 app it fails with the error: "Compile error: User defined type not defined".

Anyway here is my 97 code, if anyone could translate this into 2000 code or knows a better way of doing this the help would be a appreciated.

Dim dbs As Database, rst As Recordset
Dim fldContactID As Field, fldAttention As Field

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Attention")
Set fldContactID = [rst!ContactID]
Set fldAttention = [rst!Attention]


With rst
.AddNew
!ContactID = cboContact
!Attention = NewData
.Update
End With

rst.Close

Thanks in advance.

Steve
 
I don't recall seeing brackets placed like the ones in your code. Perhaps the compiler is having trouble with them. Here is a excerpt from your code...


Set fldContactID = [rst!ContactID]
Set fldAttention = [rst!Attention]

Change to...

Set fldContactID = rst("ContactID")
Set fldAttention = rst("Attention")

Remember that Access 2000 is primarily focused on the ADO interface. So, it may be wise to predicate your DAO declarations with "ADO.". This is just so you are specific as to which library model you are attempting to program against.

Gary
gwinn7
A+, Network+
 
You should be able to use the code as is. Just explicitly define the data objects so Access does not confuse with ADO data objects as it is doing and make sure you have a reference set to the DAO library.

Dim dbs As DAO.Database, rst As DAO.Recordset
Dim fldContactID As DAO.Field, fldAttention As DAO.Field

After closing
Set rst = Nothing

Let us know if you want to do it in ADO instead and an example could be provided.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top