|
-
May 12th, 2003, 04:24 PM
#1
Thread Starter
Member
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:
Dim sql As String
adcPayroll.CommandType = adCmdText
sql = "SELECT * FROM Employees_pay"
adcPayroll.RecordSource = sql
adcPayroll.Refresh
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
-
May 12th, 2003, 04:31 PM
#2
Addicted Member
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
-
May 12th, 2003, 04:32 PM
#3
Addicted Member
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
-
May 12th, 2003, 04:33 PM
#4
Frenzied Member
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
-
May 12th, 2003, 05:25 PM
#5
Thread Starter
Member
I am still getting the same error for some reason.
-
May 12th, 2003, 05:31 PM
#6
Thread Starter
Member
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?
-
May 12th, 2003, 09:08 PM
#7
Fanatic Member
is adcPayroll an ado control? if yes, it should be . . .
VB Code:
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!
-
May 13th, 2003, 03:24 AM
#8
Thread Starter
Member
Originally posted by Armbruster
is adcPayroll an ado control? if yes, it should be . . .
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|