Saving to a database

what is the code that could be used that when a button is pressed takes information in text3.text and text4.text and saves it into a database, witht txt3.text going into the "surname" field, and text4.text going into the "number" field.
Warsteiner99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

esolveSoftware Development ManagerCommented:
You can write data to a database using ADO:
First create a connection:

Dim cn as ADODB.Connection
Set cn = New ADODB.Connection
    ' The ConnectionString contains the path of the database.
    With cn
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & _
        "c:\WINDOWS\database.mdb"
        .Open
    End With

'then create a Recodset object:
Dim rsQuote as new ADODB.Recordset
Set rsQuote = new ADODB.Recordset

rsQuote.Open "SELECT * FROM Table", cn, adOpenStatic, adLockOptimistic
    'add information to one record
    rsQuote.AddNew
    rsQuote!QuoteID = txtQuoteID.Text
    rsQuote.Update
    rsQuote.Close
    Set rsQuote = Nothing
   

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AdamB_OpenCommented:
private sub button_click()
Dim dbs as database
dim rst as recordset

set dbs=opendatabase(filename)
set rst=dbs.openRecordset("Select * From Tablename")
rst.edit
rst.add
rst.fields("surname")=text3'.text
rst.fields("number")=text4'.text
rst.update

'If you wish to save as a new record.
'filename is the *.mdb name and path
'Tablename is the name of the table where the fields surname and number are found
'If you wish to save the data in an existing record you will need some more code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.