Results 1 to 4 of 4

Thread: Okay programmers to the thinking board!!!

  1. #1
    Guest

    Post

    Is it possible to have a command button that will update your database when clicked.

    EX. You enter some info into a textbox, then click the command button, the button then takes the data in the textbox and updates the correct table/query in the database?

    more advanced coders:
    if it can do this, can it also make a sound on the PC that the database is on, warning the user the database has been updated?

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    You absolutely may update your database when a button is clicked. In fact, I've been working on a project for the last 6 months and that's how I update the database. All you need to use is:

    Connection.Execute("SQL Statement Here")

    Where Connection is your open connection to the database.

    ------------------
    Ryan

  3. #3
    Guest

    Post

    Is there an example that I could look at. When you say connection do you mean...
    C:\database\database.mdb
    AS far as SQL statement, is there an example of this that I could see?

  4. #4
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Ok, well here's a function from my current project, I've cut out most of the unimportant stuff.

    Code:
    Public Function UpdateFields()
        Dim x As Object
        Dim i As Integer
        On Error GoTo ERROR
        For Each x In Me.Controls
            Connection.Execute ("UPDATE Invoices SET " & Mid(x.Name, 4) & "= '" & x.Text & "' WHERE invoice_number = " & txtinvoice_number.Text)
                End If
            End If
        Next x
        Exit Function
    ERROR:
        MsgBox "Error Message Here", vbOKOnly, "Error While Updating Database"
    End Function
    Here, I use ADO, and I already have an open connection to the database, called Connection, and as long as you are accessing a SQL database (Sybase SQL Server, MS SQL Server, Access, etc.) I know it will work. If you are using some other type of database that does not accept SQL statements, then I would suggest changing databases! No, I'm just kidding, but I don't know if it will work, because I've never tried it. Good luck. And if you need a good reference to creating your own SQL statement, go here.

    ------------------
    Ryan


    [This message has been edited by Gimpster (edited 02-02-2000).]

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