By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

ERROR: Object Required

100+
P: 103
Please check the following code for adding records to a database:

Im getting the error:object required in the following code( which is in bold letters)

kindly go through
[vbcode]
Private Sub cmdAdd_Click()
strdep = cbodep.Text
rs.Open "select departmentno from Departments where departmentname ='" & strdep & "' ", conn, adOpenStatic, adLockOptimistic
If Not rs.EOF Then
strdep = rs!Departmentno
End If
rs.Close
strdes = cbodes.Text
rs.Open "select DesignationsId from Designations where DesignationName = '" & strdes & "' ", conn, adOpenStatic, adLockOptimistic
If Not rs.EOF Then
strdes = rs!designationsid
End If
rs.Close
If Trim(Form2.txtgid.Text) = "" Then
MsgBox "Please enter numbers", vbOKOnly, "ERROR"
cbostate.SetFocus
ElseIf IsNumeric(txtnme.Text) Then
MsgBox "Numbers are not allowed", vbExclamation, "ERROR"
txtnme.SetFocus
ElseIf cbosex.Text = "" Then
MsgBox "Enter the valid Data", vbExclamation, "ERROR"
cbosex.SetFocus
Else
rs1.Open "select * from EmployeeDetails where GTTLID = '" & Form2.txtgid.Text & "'", conn, adOpenStatic, adLockOptimistic

If rs1.EOF Then
conn.BeginTrans
conn.Execute "insert into EmployeeDetails(GTTLID,EmployeeName,age,sex,Depart ment,Designation,DOB,DOJ,PhoneNo,MobileNo,EmailId, Address) values ('" & txtgid & "','" & txtnme & "','" & cboage & "','" & cbosex & "'," & strdep & ",'" & strdes & "','" & dtdob & "','" & dtdoj & "','" & txtphne & "','" & txtmob & "','" & txtmail & "','" & txtadd & "')"
MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
Else
MsgBox "duplicate record"
End If
rs1.Close
Set rs1 = Nothing
End If
end sub
[/vbcode]


thanks in advance:
May 8 '08 #1
Share this Question
Share on Google+
2 Replies


lotus18
100+
P: 866
Please check the following code for adding records to a database:

Im getting the error:object required in the following code( which is in bold letters)

kindly go through
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2. strdep = cbodep.Text
  3.  rs.Open "select departmentno from Departments where departmentname ='" & strdep & "' ", conn, adOpenStatic, adLockOptimistic
  4. If Not rs.EOF Then
  5.  strdep = rs!Departmentno
  6. End If
  7.  rs.Close
  8.  strdes = cbodes.Text
  9.  rs.Open "select DesignationsId from Designations where DesignationName = '" & strdes & "' ", conn, adOpenStatic, adLockOptimistic
  10. If Not rs.EOF Then
  11.  strdes = rs!designationsid
  12. End If
  13. rs.Close
  14. If Trim(Form2.txtgid.Text) = "" Then
  15. MsgBox "Please enter numbers", vbOKOnly, "ERROR"
  16. cbostate.SetFocus
  17. ElseIf IsNumeric(txtnme.Text) Then
  18.    MsgBox "Numbers are not allowed", vbExclamation, "ERROR"
  19.    txtnme.SetFocus
  20. ElseIf cbosex.Text = "" Then
  21.    MsgBox "Enter the valid Data", vbExclamation, "ERROR"
  22.    cbosex.SetFocus
  23. Else
  24. rs1.Open "select * from EmployeeDetails where GTTLID = '" & Form2.txtgid.Text & "'", conn, adOpenStatic, adLockOptimistic
  25. If rs1.EOF Then
  26. conn.BeginTrans
  27.   conn.Execute "insert into EmployeeDetails(GTTLID,EmployeeName,age,sex,Department,Designation,DOB,DOJ,PhoneNo,MobileNo,EmailId,Address) values ('" & txtgid & "','" & txtnme & "','" & cboage & "','" & cbosex & "'," & strdep & ",'" & strdes & "','" & dtdob & "','" & dtdoj & "','" & txtphne & "','" & txtmob & "','" & txtmail & "','" & txtadd & "')"
  28. MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
  29.  Else
  30.   MsgBox "duplicate record"
  31.   End If
  32.  rs1.Close
  33.  Set rs1 = Nothing
  34.    End If
  35. end sub
  36.  
thanks in advance:
Enclosed your given codes with code tags for easy for us to understand.
Did you declared your rs1 as your new recordset? I cannot see your Active Connection or did I miss it?

Rey Sean
May 8 '08 #2

100+
P: 103
Enclosed your given codes with code tags for easy for us to understand.
Did you declared your rs1 as your new recordset? I cannot see your Active Connection or did I miss it?

Rey Sean


....yes i got it.....rs1 was not declared,,,,,,,,,,,,,,,,,

Active Connection............

Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rs1 As New ADODB.Recordset

Public rsid As New ADODB.Recordset
Public rsnme As New ADODB.Recordset
Public rsdept As New ADODB.Recordset
Public rsdes As New ADODB.Recordset
Public Sub Main()
conn.Open "Provider=sqloledb.1;User ID=sa;password=;Data Source=STATISTICS;Initial Catalog=Nicks"
'conn.Open "Provider=sqloledb.1;User ID=sa;password=;Data Source=HS445;Initial Catalog=EXMP"
Form1.Show
End Sub


rs1 was declared now only.............

Nikhita(Nicks)
May 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.