Results 1 to 8 of 8

Thread: Trouble adding new record to Access DB

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Location
    Las Vegas, NV
    Posts
    45

    Trouble adding new record to Access DB

    I keep getting "Compile Error - Method or data member not found" for .AddNew in my code. What am I doing wrong here?

    VB Code:
    1. Dim sql As String
    2. adcPayroll.CommandType = adCmdText
    3. sql = "SELECT * FROM Employees_pay"
    4. adcPayroll.RecordSource = sql
    5. adcPayroll.Refresh
    6. adcPayroll.AddNew
    7.     adcPayroll!FirstName = txtFirstName.Text
    8.     adcPayroll!LastName = txtLastName.Text
    9.     adcPayroll!DepartmentName = cmbDepartment.Text
    10.     adcPayroll!Shift = lstShift.Text
    11.     adcPayroll!SocialSecurityNumber = mskID.Text
    12.     adcPayroll!Salary = txtSalary.Text
    13.     adcPayroll!PayrollEndingDate = mskDate.Text
    14.     adcPayroll!Dependents = lstDependents.Text
    15.     adcPayroll!HoursWorked = txtHours.Text
    16.     adcPayroll!Shift = lstShift.Text
    17.     adcPayroll.Update
    18. End Sub

  2. #2
    Addicted Member AmmerBow's Avatar
    Join Date
    Sep 2000
    Posts
    195
    Code:
        Dim Db As ADODB.Connection
        Set Db = New ADODB.Connection
        With Db
            .Provider = "Microsoft.Jet.OLEDB.4.0"
            .Open "c:\accessdatabase.mdb"
        End With
    
        Dim rs As ADODB.Recordset
        Set rs = New ADODB.Recordset
        rs.CursorLocation = adUseClient
        
        rs.Open "Select * From [Employees_pay]", Db, adOpenKeyset, adLockOptimistic
    
    adcPayroll.AddNew
        adcPayroll!FirstName = txtFirstName.Text
        adcPayroll!LastName = txtLastName.Text
        adcPayroll!DepartmentName = cmbDepartment.Text
        adcPayroll!Shift = lstShift.Text
        adcPayroll!SocialSecurityNumber = mskID.Text
        adcPayroll!Salary = txtSalary.Text
        adcPayroll!PayrollEndingDate = mskDate.Text
        adcPayroll!Dependents = lstDependents.Text
        adcPayroll!HoursWorked = txtHours.Text
        adcPayroll!Shift = lstShift.Text
        adcPayroll.Update
    End Sub
    Amiga 500 was here.

  3. #3
    Addicted Member AmmerBow's Avatar
    Join Date
    Sep 2000
    Posts
    195
    If this code is inside Access and not VB then use

    Code:
        Dim rs As ADODB.Recordset
        Set rs = New ADODB.Recordset
        rs.CursorLocation = adUseClient
        
        rs.Open "Select * From [Employees_pay]", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    
    adcPayroll.AddNew
        adcPayroll!FirstName = txtFirstName.Text
        adcPayroll!LastName = txtLastName.Text
        adcPayroll!DepartmentName = cmbDepartment.Text
        adcPayroll!Shift = lstShift.Text
        adcPayroll!SocialSecurityNumber = mskID.Text
        adcPayroll!Salary = txtSalary.Text
        adcPayroll!PayrollEndingDate = mskDate.Text
        adcPayroll!Dependents = lstDependents.Text
        adcPayroll!HoursWorked = txtHours.Text
        adcPayroll!Shift = lstShift.Text
        adcPayroll.Update
    End Sub
    Amiga 500 was here.

  4. #4
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    You'd need to declare or set your object variable as new adodb.recordset first and then try to open.

    assuming your connection (adoCNN) is already open then:
    Set adcPayroll = New ADODB.recordset
    adcPayroll.Open strSQL, adoCNN
    McGenius

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2003
    Location
    Las Vegas, NV
    Posts
    45
    I am still getting the same error for some reason.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2003
    Location
    Las Vegas, NV
    Posts
    45
    Basically when I type adcPayroll. and all the options come up in the drop down box, "AddNew" isn't there. Is there some sort of property I need to change?


  7. #7
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    is adcPayroll an ado control? if yes, it should be . . .

    VB Code:
    1. adcPayroll.Recordset.AddNew

    That should get you going, but to save headaches in the future, learn ADO. Because if I've said it once, I've said it a thousand times . . . DATA-BOUND CONTROLS SUCK!
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2003
    Location
    Las Vegas, NV
    Posts
    45
    Originally posted by Armbruster
    is adcPayroll an ado control? if yes, it should be . . .

    VB Code:
    1. adcPayroll.Recordset.AddNew

    That should get you going, but to save headaches in the future, learn ADO. Because if I've said it once, I've said it a thousand times . . . DATA-BOUND CONTROLS SUCK!
    Thanks.

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