Re: Write to table

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Yes, you can use either method to insert records.

Using unbound forms involves extra work though, loading existing records,
keeping track of whether this is an existing record (so you need to execute
an UPDATE) or a new record (so you need to execute an INSERT), and making
sure you don't do it multiple times as an impatient user clicks repeatedly.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Zoltar54" <Zoltar54@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EEA1F98C-487D-4CDE-B00B-6CB8963F1471@xxxxxxxxxxxxxxxx
Allen,
Would example A work for me if I wanted to enter data from an unbound
textbox on a form to a record table?

Z

"Allen Browne" wrote:

Couple of options:
a) Execute an Append query statement.
b) OpenRecordset, and add the record.

Example of (a):
===========
Dim strSql As String
strSql = "INSERT INTO Table1 (Field1, Field2, Field3), " & _
"6 AS F1, 'Springfield' AS F2, #1/1/2006# AS F3"
dbEngine(0)(0).Execute strSql, dbFailOnError

To get the SQL statement right, you can mock up a query typing any values
in. Then change it to an Append query (Append on Query menu), and switch
to
SQL view (View menu) to see the example.

Example of (b):
===========
Dim rs As DAO.Recordset
Set rs = dbEngine(0)(0).OpenRecordset("Table1")
rs.AddNew
rs!Field1 = 6
rs!Field2 = "Springfield"
rs!Field3 = #1/1/2006#
rs.Update
rs.Close
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Vsn" <vsn at hotmail> wrote in message
news:uvMPin%23cGHA.1456@xxxxxxxxxxxxxxxxxxxxxxx

Can some one tell me if its possible to add data to a table, in a bit
of a
sameway data can be retrived by aggregate functions? And if this is
possible what the code would be to use it from VBA.





.



Relevant Pages

  • Re: Duplicate the record in form and subform and Subbforms within
    ... and then uses the key value in an Append query string to ... Essentially you have a loop within a loop, ... If you have further levels of subform, you have more 'middle' layers here. ... Allen Browne - Microsoft MVP. ...
    (microsoft.public.access.formscoding)
  • Re: Adding record to table
    ... of writing a record using Recordset.AddNew vs. an Append Query. ... the text boxes bound, and go to a new record when you open the form? ... If you really want to use unbound boxes, then have a button that opens an ... I have an unbound form with a mess of unbound text boxes. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Adding record to table
    ... of writing a record using Recordset.AddNew vs. an Append Query. ... the text boxes bound, and go to a new record when you open the form? ... If you really want to use unbound boxes, then have a button that opens an ... I have an unbound form with a mess of unbound text boxes. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Default User ID and Date
    ... Nick ... > You can use the function call in your Append query. ... > Allen Browne - Microsoft MVP. ... >> UserID field when a the record is added. ...
    (microsoft.public.access.formscoding)
  • Re: Multiple record creation
    ... use the values in the unbound form in an Append Query. ... > used for data entry and use a different form for editing. ... > row source still coming from the data in the ProdData ...
    (microsoft.public.access.macros)