Committing Data to Tables

J

JJ

It has been a long time since I built an application in Access so
forgive me for the newbie-level question. I want to create a form where
you can add data from a text box, call it txtData.

I want the user to type in a value in the text box and hit and "Add
Data" button. I do NOT want to make the text box a bounded control
because I want to run the text box value through some validation code
first and only commit the data to the table (tblData), if it passes
through the validation scheme. Assuming the data is valid, what is the
code to commit the txtData value to tblData?

I recall using recordsets before to do this but that was when I was
building the application in Visual Basic and connecting the application
to the Access database. This application is completely built in Access.
Is it the same process?

In either case, could someone help me out with the code? If it helps, I
am using Access 2002.

Thanks!
JJ
 
G

George Nicholson

Whether bound or not, you would use the textbox's BeforeUpdate event to run
your validation code (or the Form_BeforeUpdate for the record as a whole).
Both can be Canceled if validation fails.

If the underlying recordset of the Form is updateable, I suggest you use a
bound control. The only times I've ever had to write DAO or ADO code to
manually update/add records is if I was displaying an un-updateable
recordset on a form (i.e., a crosstab query, etc.)

But, to answer your question, the DAO code to add a record to a recordset
manually would probably be exactly what you wrote in VB. At its simplest, it
would be something like:

With rstTemp
.AddNew
!FirstName = Me.txtFirstName
!LastName = Me.txtLastName
.Update
End With

If you are just editing, not adding, replace .AddNew with .Edit to modify
the Current record.

ADO code (for the above) would be identical, afaik.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top