VB6 Add a record to MySQL with cancel option

Posted on 2011-10-27
Last Modified: 2013-12-25
I want to do simple record manipulation.  I have 3 buttons on a form:  New, Save, Cancel.

If I start with this sub (connection works correctly), what's the proper Save/Cancel?

Private Sub btnNewOne_Click()
     txtField1.text = ""
     txtField2.text = ""
     txtField3.text = ""
End Sub

Open in new window

Question by:kkbenj
    LVL 14

    Accepted Solution

    I would suggest a popup screen or form to go along with this process...

    on New ' show the form or perhaps frame

    on cancel or save...hide the frame

    I would also encourage data validation in the save...
    Perhaps require field1 be populated...
    Private Sub btnNewOne_Click()
         txtField1.text = ""
         txtField2.text = ""
         txtField3.text = ""
         frNewData.Visible = True
    End Sub
    Private Sub btnSaveOne_Click()
         if trim(txtfield1.Text) = "" then
            msgbox "Please enter a value in Field 1" 
            exit sub
         end if  
         goRecSet!Field1 = txtfield1.text
         goRecSet!Field2 = txtfield3.text
         goRecSet!Field3 = txtfield4.text
         frNewData.visible = false 
    End Sub
    Private Sub btnCancel_Click()
         ' return values to previous row ?
         if goRecSet.recordcount > 0 then
            goto LeaveNow
         End If 
         txtField1.text = goRecSet!Field1
         txtField2.text = goRecSet!Field2
         txtField3.text = goRecSet!Field3
         frNewData.visible = false
    End Sub

    Open in new window


    Author Closing Comment

    It's like you read my mind.  Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now