Click to See Complete Forum and Search --> : writing to databases
spandex44
Dec 14th, 1999, 12:27 AM
Hi! I've asked this question before, but I didn't really understand the response. How do you write data to a field of an Access database? I would like to be able to choose which column to put the data in, too.
------------------
Regards,
Alexander McAndrew
VB Zone
http://gsenterprise.server101.com
With DAO, assuming you have no datacontrol:
In the general declarations area try:
Dim dbMyDatabase as Database
Dim rstMyRecordset as Recordset
Now in the form_load event, let your application know which database and recordset to use:
Set dbMyDatabase = Opendatabase("MyDatabase.mdb")
Set rstMyRecordset = dbMyDatabase.OpenRecordset("MyRecordset", dbOpenDynaset)
Now, in the save event or anytime you wish to write information to the database you code:
rstMyRecordset.AddNew
rstMyRecordset!FieldInDatabase = cboCombobox.text
rstMyRecordset.Update
rstMyRecordset: The recordset(table) you named in the general declarations and then identified in form_load.
FieldInDatabase: The name of the column in the database table.
Hope that helped,
Nick
spandex44
Dec 14th, 1999, 09:22 PM
thanks
Is there a way to do it with a data control. That would make everything a lot easier for me.
Thanks for the help.
------------------
Regards,
Alexander McAndrew
VB Zone
http://gsenterprise.server101.com
JHausmann
Dec 15th, 1999, 05:23 AM
Bound controls, as they're currently implemented, are good only for populating fields. I've had nothing but grief in those instances where I've used them. Error messages that have little to do with the problem cause and 'flaky' behavior are the primary reasons. In the long run, you're much better off doing it yourself...
Clunietp
Dec 15th, 1999, 03:36 PM
I agree with JHausmann, but I also agree that it's much easier (but sloppier) with the data control.....
Before editing:
Data1.Recordset.Edit 'FOR DAO ONLY
here the user can change the contents of the bound textbox
text1.text = "My New Value"
When done editing
Data1.Recordset.Update 'commit changes
- or -
Data1.Recordset.CancelUpdate 'cancel changes
==================
This UBB code isn't too bad....
Tom
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.