CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2012
    Posts
    2
    Sir can you please help me on my codes about Save Button I wonder what's wrong on my code here is my code:
    Code:
    Dim ctrl As Control
    Dim Adodc1 As Adodc
    
    Validate_inputs
       
       If ValidateEntries Then
       'Confirm Saving Records...
        Adodc1.Recordset.Update
       Else
        Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
        Adodc1.Recordset.Fields("Patient No.") = Text2.Text
        Adodc1.Recordset.Fields("Patient Name") = Text3.Text
        Adodc1.Recordset.Fields("Age") = Text4.Text
        Adodc1.Recordset.Fields("BirthDate") = Text5.Text
        Adodc1.Recordset.Fields("Address") = Text6.Text
        Adodc1.Recordset.Fields("Telephone No") = Text7.Text
        Adodc1.Recordset.Fields("Civil Status") = Text8.Text
        Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
        Adodc1.Recordset.Fields("Room Type") = Text10.Text
        Adodc1.Recordset.Fields("Room No.") = Text11.Text
        Adodc1.Recordset.Fields("Guardian") = Text12.Text
        Adodc1.Recordset.Fields("GAddress") = Text13.Text
        Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
        Adodc1.Recordset.Update
        Text1.Enabled = False
        Text2.Enabled = False
        Text3.Enabled = False
        Text4.Enabled = False
        Text5.Enabled = False
        Text6.Enabled = False
        Text7.Enabled = False
        Text8.Enabled = False
        Text9.Enabled = False
        Text10.Enabled = False
        Text11.Enabled = False
        Text12.Enabled = False
        Text13.Enabled = False
        Text14.Enabled = False
        CmdSave.Enabled = True
    End If
    End Sub

    Sir What is the Code for Edit,Cancel And Search? How to code a fast pace of searching?
    Last edited by Cimperiali; April 5th, 2012 at 07:08 AM. Reason: Same posts from same author

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6 Save Button Command

    You are updating the record BEFORE getting info from the fields (Unless you do it twice). Also, might have to format for the correct data-type of your fields
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: VB6 Save Button Command

    There is no special code to edit.
    If you have unbound textfields, you fill the textfields with the contents of the record's fields and let the user edit each field.
    The Save button mus then do this (in Pseudocode)
    Code:
    btnSave_Click()
      If ValidateAllInput then
         Recordset.Field("FieldName) = Textx.Text
         ...repeat for all fields
         Recordset.Update
      EndIf
    End Sub
    As long as you don't call RecordsetUpdate no change to the record should occur.
    If you make a new record, you first clear all textfields, then you do
    Recordset.AddNew (to add a new record to the table)
    Then again you let the user entwer data.
    The Save Button works exactly like before.
    The Cancel button should simple refill the textboxes with the fields from the recordset.
    But in case you have added a new record, you have to do
    Recordset.CancelUpdate
    to remove the record you had added with .AddNew
    and then display the record you had displayed before.
    There are some features of the Recordset object which help reminding which was the last record.Read up on the .BookMark property.
    Also I'd suggest you look for small samples of complete working code.

  4. #4
    Join Date
    Apr 2012
    Posts
    2

    Re: VB6 Save Button Command

    Sir what is the with this when i run it and input an example Information then when i click save button it didn't work here is the code:

    Dim ctrl As Control
    Dim Adodc1 As Adodc

    If ValidateEntries Then
    'Confirm Saving Records...
    If MsgBox("Click Ok to Save", vbInformation + vbOKCancel) = vbOK Then
    Adodc1.Recordset.AddNew 'New Record
    Else
    End If
    Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
    Adodc1.Recordset.Fields("Patient No.") = Text2.Text
    Adodc1.Recordset.Fields("Patient Name") = Text3.Text
    Adodc1.Recordset.Fields("Age") = Text4.Text
    Adodc1.Recordset.Fields("BirthDate") = Text5.Text
    Adodc1.Recordset.Fields("Address") = Text6.Text
    Adodc1.Recordset.Fields("Telephone No") = Text7.Text
    Adodc1.Recordset.Fields("Civil Status") = Text8.Text
    Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
    Adodc1.Recordset.Fields("Room Type") = Text10.Text
    Adodc1.Recordset.Fields("Room No.") = Text11.Text
    Adodc1.Recordset.Fields("Guardian") = Text12.Text
    Adodc1.Recordset.Fields("GAddress") = Text13.Text
    Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
    Adodc1.Recordset.Update
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
    Text5.Enabled = False
    Text6.Enabled = False
    Text7.Enabled = False
    Text8.Enabled = False
    Text9.Enabled = False
    Text10.Enabled = False
    Text11.Enabled = False
    Text12.Enabled = False
    Text13.Enabled = False
    Text14.Enabled = False
    CmdSave.Enabled = True
    Else

    End If
    End Sub

  5. #5
    Join Date
    Sep 2006
    Posts
    635

    Re: VB6 Save Button Command

    Quote Originally Posted by Sulapas View Post
    it didn't work here is the code:
    what didn't work??

    data is not add in database.
    it shows error message.
    .
    .
    .

    so on.

    pleae you can explain a bit more
    so we would can help you.

  6. #6
    Join Date
    Apr 2012
    Posts
    2

    Re: VB6 Save Button Command

    sorry for the post the code that didn't work is this:
    [code]
    Dim ctrl As Control
    Dim Adodc1 As Adodc

    If ValidateEntries Then
    'Confirm Saving Records...
    If MsgBox("Click Ok to Save", vbInformation + vbOKCancel) = vbOK Then
    Adodc1.Recordset.AddNew 'New Record
    Else
    End If
    Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
    Adodc1.Recordset.Fields("Patient No.") = Text2.Text
    Adodc1.Recordset.Fields("Patient Name") = Text3.Text
    Adodc1.Recordset.Fields("Age") = Text4.Text
    Adodc1.Recordset.Fields("BirthDate") = Text5.Text
    Adodc1.Recordset.Fields("Address") = Text6.Text
    Adodc1.Recordset.Fields("Telephone No") = Text7.Text
    Adodc1.Recordset.Fields("Civil Status") = Text8.Text
    Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
    Adodc1.Recordset.Fields("Room Type") = Text10.Text
    Adodc1.Recordset.Fields("Room No.") = Text11.Text
    Adodc1.Recordset.Fields("Guardian") = Text12.Text
    Adodc1.Recordset.Fields("GAddress") = Text13.Text
    Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
    Adodc1.Recordset.Update
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
    Text5.Enabled = False
    Text6.Enabled = False
    Text7.Enabled = False
    Text8.Enabled = False
    Text9.Enabled = False
    Text10.Enabled = False
    Text11.Enabled = False
    Text12.Enabled = False
    Text13.Enabled = False
    Text14.Enabled = False
    CmdSave.Enabled = True
    Else

    End If
    End Sub
    [code]

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6 Save Button Command

    Edit the post, and add / to the CLOSING TAG of code.


    Code:
     CODE]  /CODE]
    Also, what does the SAVE button code look like?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Talking Re: VB6 Save Button Command

    Try the following .

    Code:
    If ValidateEntries Then
    Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
    Adodc1.Recordset.Fields("Patient No.") = Text2.Text
    Adodc1.Recordset.Fields("Patient Name") = Text3.Text
    Adodc1.Recordset.Fields("Age") = Text4.Text
    Adodc1.Recordset.Fields("BirthDate") = Text5.Text
    Adodc1.Recordset.Fields("Address") = Text6.Text
    Adodc1.Recordset.Fields("Telephone No") = Text7.Text
    Adodc1.Recordset.Fields("Civil Status") = Text8.Text
    Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
    Adodc1.Recordset.Fields("Room Type") = Text10.Text
    Adodc1.Recordset.Fields("Room No.") = Text11.Text
    Adodc1.Recordset.Fields("Guardian") = Text12.Text
    Adodc1.Recordset.Fields("GAddress") = Text13.Text
    Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
    Adodc1.Recordset.Update
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
    Text5.Enabled = False
    Text6.Enabled = False
    Text7.Enabled = False
    Text8.Enabled = False
    Text9.Enabled = False
    Text10.Enabled = False
    Text11.Enabled = False
    Text12.Enabled = False
    Text13.Enabled = False
    Text14.Enabled = False
    CmdSave.Enabled = True
    End if

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6 Save Button Command

    Pretty hard without a NEW record... Come on. HELP others.

    Your code omitted a line.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Talking Re: VB6 Save Button Command

    Hi David ,really i did not notice .
    Code:
    If ValidateEntries Then
    Adodc1.recordset.Addnew
    Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
    Adodc1.Recordset.Fields("Patient No.") = Text2.Text
    Adodc1.Recordset.Fields("Patient Name") = Text3.Text
    Adodc1.Recordset.Fields("Age") = Text4.Text
    Adodc1.Recordset.Fields("BirthDate") = Text5.Text
    Adodc1.Recordset.Fields("Address") = Text6.Text
    Adodc1.Recordset.Fields("Telephone No") = Text7.Text
    Adodc1.Recordset.Fields("Civil Status") = Text8.Text
    Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
    Adodc1.Recordset.Fields("Room Type") = Text10.Text
    Adodc1.Recordset.Fields("Room No.") = Text11.Text
    Adodc1.Recordset.Fields("Guardian") = Text12.Text
    Adodc1.Recordset.Fields("GAddress") = Text13.Text
    Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
    Adodc1.Recordset.Update
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
    Text5.Enabled = False
    Text6.Enabled = False
    Text7.Enabled = False
    Text8.Enabled = False
    Text9.Enabled = False
    Text10.Enabled = False
    Text11.Enabled = False
    Text12.Enabled = False
    Text13.Enabled = False
    Text14.Enabled = False
    CmdSave.Enabled = True
    End if

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

Featured