CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Location
    LPC, Philippines
    Posts
    2

    Problem on .AddNew function

    hi guys, i have a small problem on my .AddNew function
    hope you can help me on this...

    so here's my problem... every time i click my "Save Info" button, which is by the way my .AddNew function, it starts to mess up my database, how?

    every time i started to add new information of an employee on my database it skips 2 rows from the table where that information must be saved, then the .AddNew function will save the information to the 3rd row and if i add again another information, the .AddNew function will overwrite the saved information on the 3rd row and replaces the information their with the newly added one.

    so basically all the information that i have saved and i will be saving is stucked on the 3rd row!

    hope you guys could help me on this.... thanks very much !

    here's my coding for my "Save Info" button




    Private Sub btnSave_Click()

    If txtID.Text = "" Or txtLN.Text = "" Or txtFN.Text = "" Or txtMN.Text = "" Or txtADD.Text = "" Or txtPN.Text = "" Or txtEM.Text = "" Or txtDB.Text = "" Or txtDH.Text = "" Then

    MsgBox "Incomplete Data..", vbCritical, "Empty"

    Else

    Adodc1.Recordset.AddNew
    Adodc1.Recordset.Fields("Employee ID").Value = txtID.Text
    Adodc1.Recordset.Fields("Last Name").Value = txtLN.Text
    Adodc1.Recordset.Fields("First Name").Value = txtFN.Text
    Adodc1.Recordset.Fields("Middle Name").Value = txtMN.Text
    Adodc1.Recordset.Fields("Address").Value = txtADD.Text
    Adodc1.Recordset.Fields("Phone no").Value = txtPN.Text
    Adodc1.Recordset.Fields("e-Mail").Value = txtEM.Text
    Adodc1.Recordset.Fields("Date Hired").Value = txtDH.Text
    Adodc1.Recordset.Fields("Date of Birth").Value = txtDB.Text
    Adodc1.Recordset.Fields("Company Division and Job Designation").Value = lblDivisionDesignation.Caption
    Adodc1.Recordset.Fields("Hourly Pay").Value = lblHP.Caption
    Adodc1.Recordset.Fields("Job Status").Value = lblJS.Caption
    Adodc1.Recordset.Update
    Adodc1.Recordset.Requery
    Adodc1.Refresh

    MsgBox "One record Appended"

    txtID.Text = ""
    txtLN.Text = ""
    txtFN.Text = ""
    txtMN.Text = ""
    txtADD.Text = ""
    txtPN.Text = ""
    txtEM.Text = ""
    txtDB.Text = ""
    txtDH.Text = ""
    lblJS.Caption = ""
    lblHP.Caption = ""
    lblDivisionDesignation.Caption = ""

    End If


    End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,583

    Re: Problem on .AddNew function

    Do it the OTHER way.

    Have them click a button to ADD a record. Don't save it, UNLESS it passes, and THEN, and only then, put it into your DB.

    btw- Bound Controls are EVIL, as I've said here
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2012 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
    Oct 2010
    Location
    LPC, Philippines
    Posts
    2

    Re: Problem on .AddNew function

    thanks for you reply sir dglienna, i 'll try this now right away!, also i have read about your post on "Bound Controls are EVIL" and i have read a lot of spoilers

    our professor haven't discussed any SQL-related stuffs yet, but i learned a lot on that post of yours.

    again thanks, hope i 'll be able to finish my project by next week

+ Reply to Thread

Bookmarks

Posting Permissions

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



HTML5 Development Center

Click Here to Expand Forum to Full Width