adding new record to table from form using cmd buttn

  • Thread starter Thread starter kim nguyen
  • Start date Start date
K

kim nguyen

this question is copied from and entry @ dev shed, but i
have the same question:

I have several fields on a form and I need to be able to
add the info from the fields to an existing table as a new
record.

For example:
Take the info from Text1 & Text2 and put it as new record
in the table called 'tblAnalysts' under the fields 'Name'
(for text1) and 'Locaiton' (for text2).

I pretty much need to know how to access a table (add
records, remove records, update/change records), but
without having the table linked to the form or text boxes.

thanks!
 
Hi Kim,

My name is Dennis Schmidt. Thank you for using the Microsoft Windows
Installer Newsgroups.

The following code example should get you started. You would need to call
the code on some event once the two fields had been populated (like the
OnClick of a button).

Function AddNewRecord()
Dim MyDb As Database, MyRs As Recordset, Criteria As String
Set MyDb = CurrentDb()
Set MyRs = MyDb.OpenRecordset("tblAnalysts", dbOpenDynaset)
MyRs.AddNew
MyRs![Name] = Forms!FormName!Text1
MyRs![Location] = Forms!FormName!Text2
MyRs.Update
MyRs.Close
MyDb.Close
End Function

I hope this helps! If you have additional questions on this topic, please
reply to this posting.

Need quick answers to questions like these? The Microsoft Knowledge Base
provides a wealth of information that you can use to troubleshoot a problem
or answer a question! It's located at
http://support.microsoft.com/support/c.asp?M=F>.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2001 Microsoft Corporation. All rights
reserved.

Regards,
Dennis Schmidt
Microsoft Support
 
Back
Top