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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Into An Access Database, from TextBoxes

Status
Not open for further replies.

Atajames

Technical User
Jul 17, 2002
11
US
Hi Guys!

I have a Microsoft Access 7.0 database that I built from the Vis.. Data Manager. I also have another form with textboxes. I'm having troubles adding the textboxes data into the database automaitically.

Please, I urgently need your help
 
Look into the Data control. You should be able to bind it a table in your database and then you should be able bind the text boxes to the data control.

Do a search on this site for the 'datacontrol' or the 'adodc' and you should get some results.

Thanks and Good Luck!

zemp
 
Thanks Zemp!

I did the search, but I couldn't find an answer to my problem. In fact many problems related to mine weren't answered.

These are my codes:

Private sub cmdSubmit_click()
frmtrans.show
frmtrans.data1.recordset.addnew
frmtrans.txtfields(0)=frmcustumer.txtId.text
frmtrans.txtfields(1)=frmcustumer.txtname.text
frmtrans.txtfields(2)=frmcustumer.txtphone.text

I thought these would add the record in the customer form into the database, using the datacontrol. What else do I need?

Please help!

James!
 
Try adding the following line at the end of your code.

frmtrans.data1.recordset.update

Whenever you are working with a recordset and you are editing or adding a new record then you have to update it in some way for it to be written to the database. The syntax will depend on what tools you are using but the logic remains.

1. get record (new or existing)
2. make changes
3. update database Thanks and Good Luck!

zemp
 
I entered this line code at the bottom:

frmtrans.data1.recordset.update

I now have the "run-Time Error 3426", that points to the new code and says: 'This action was cancelled by an associated object'.

I'm still stock.

Thanks!
 
Hi Zemp!

I also thought about using the "INSERT" statement to insert record in my access database. Do you know how to write the codes? In case you do please help me do so.

James
 
I just finished some testing using an ADO data control. I don't usually use bound controls so I had to refresh my memory. It is found in Project-components, select Microsoft ADO Data Control 6.0. I added the ADODC to a form and bound it to an Access database and set the command type to adcmdtable and the recordsource to the table I wanted. I set the EOFAction property to adDoAddNew.

I then added the required number of text boxes and bound them to the ADO data control and the specific field. The control allowed me to browse the records in the database and when I reached the end of the recordset (EOF) it allowed me to add a new record. This record was added when i moved to the previous record. So far no code was written.

I added a button to add a new record and placed the following code in it.

Private Sub cmdAdd_Click()
Adodc1.Recordset.AddNew
End Sub

This emptied my text boxes so I could add a new record and when I moved to a new record the information was saved.

Seems to me that if you bind your text boxes then you don't have to reference them when you add a new record. I also have the following code in a save button. It commits the new record and then keeps the new data in the bound text boxes.

Private Sub cmdSave_Click()
Adodc1.Recordset.MoveLast
End Sub

I hope that this is more helpful. If you want I can send you my small test project, just email me at zemanpw@hotmal.com


Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top