473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

AddNew Method of ADO

38
Hello,
I'm trying to insert a new record in my recordset using AddNew method. I can't figure out how to declare values for the controls in my recordset. Can someone give me an example.
Thank you in advance for your help.
Salzan
Feb 13 '08 #1
4 3664
ADezii
8,834 Expert 8TB
Hello,
I'm trying to insert a new record in my recordset using AddNew method. I can't figure out how to declare values for the controls in my recordset. Can someone give me an example.
Thank you in advance for your help.
Salzan
Here is a simple, generic Template you can use to Add Records to a Table via the AddNew Method, but first a couple of Assumptions:
  1. Table Name ==> Table1
  2. Fields in Table 1
    1. Field1 (TEXT)
    2. Field2 (LONG)
    3. Field3 (DATE)
  3. Methodology used: DAO
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  2.  
  3. Set MyDB = CurrentDb()
  4. Set MyRS = MyDB.OpenRecordset("Table1", dbOpenDynaset)
  5.  
  6. With MyRS
  7.   .AddNew
  8.     ![Field1] = "Hello World!"
  9.     ![Field2] = 876543
  10.     ![Field3] = #12/12/1998#
  11.   .Update
  12. End With
  13.  
  14. MyRS.Close
  15. Set MyRS = Nothing
Feb 13 '08 #2
Or if not using the 'with' statement it would be

MyRS![Field1]="text"
Feb 13 '08 #3
salzan
38
Than you and if I'm not hardcoding the values I assume that I can reference the variable names containing the value, correct?
Feb 13 '08 #4
ADezii
8,834 Expert 8TB
Than you and if I'm not hardcoding the values I assume that I can reference the variable names containing the value, correct?
Yes, that is correct:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  2.  
  3. Set MyDB = CurrentDb()
  4. Set MyRS = MyDB.OpenRecordset("Table1", dbOpenDynaset)
  5.  
  6. With MyRS
  7.   .AddNew
  8.     ![Field1] = strStringVariable
  9.     ![Field2] = lngLongVariable
  10.     ![Field3] = dteDateVariable
  11.   .Update
  12. End With
  13.  
  14. MyRS.Close
  15. Set MyRS = Nothing
Feb 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Jan van Veldhuizen | last post by:
I have an application which is running fine with MS SqlServer, but it should be working with Oracle as weel. At a lot of places we rely upon the ADO Recordset to return incremented identity...
2
by: Tim Marshall | last post by:
ODBC situation, Access 97, here is the code and I've marked where Access coughs up. The Access error message is 3027, can't update, database is read only. The Oracle table in question has a...
1
by: Jon Trelfa | last post by:
I have been fighting with this script for several days and I'm finally at the end of my rope. Here's the scenario: -I have to add an entry into 1 table, called "calendar" -I must retrieve the...
2
by: William Ortenberg | last post by:
I'm creating a new row in a table with via the AddNew method, where the table ID is an Autonumber field. I want to capture the value of the ID after I create the row. There are no other unique...
2
by: guy | last post by:
if i use Generics.AddNew how do I pass an object to the items constructor? I have a set of class all inheriting from a base class, all requiring one parameter on their constructor - the data...
1
by: Leonardo | last post by:
Hi. I'm trying to build my first application with database access using VB 2005. I'm a VB 6 programmer and learning everything again has been challenging. I managed to write a code using some tips...
8
by: MLH | last post by:
Here's a snippet from A97 HELP on AddNew... The record that was current before you used AddNew remains current. If you want to make the new record current, you can set the Bookmark property to...
5
by: amey.gupte | last post by:
Hi, I am using the AddNew function in VBA to populate my access table from data in excel. The following is the piece of code: With WriteRS .AddNew !column_Names(0) = "acctNo" !B = "CoName"...
10
by: fniles | last post by:
In VB6 to add a new record in a recorset, you can use the Addnew method, then set each column's value, then call the Update method. How can I do this in VB.NET ? Thank you. VB6: Private m_rs...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.