Results 1 to 5 of 5

Thread: writing to databases

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    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


  2. #2
    Guest

    Post

    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


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    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


  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    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...

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width