ERROR: Object Required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    ERROR: Object Required

    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, adLockOptimisti c
    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, adLockOptimisti c
    If Not rs.EOF Then
    strdes = rs!designations id
    End If
    rs.Close
    If Trim(Form2.txtg id.Text) = "" Then
    MsgBox "Please enter numbers", vbOKOnly, "ERROR"
    cbostate.SetFoc us
    ElseIf IsNumeric(txtnm e.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.Te xt & "'", conn, adOpenStatic, adLockOptimisti c

    If rs1.EOF Then
    conn.BeginTrans
    conn.Execute "insert into EmployeeDetails (GTTLID,Employe eName,age,sex,D epartment,Desig nation,DOB,DOJ, PhoneNo,MobileN o,EmailId,Addre ss) 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:
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by Vbbeginner07
    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
    [code=vb]
    Private Sub cmdAdd_Click()
    strdep = cbodep.Text
    rs.Open "select departmentno from Departments where departmentname ='" & strdep & "' ", conn, adOpenStatic, adLockOptimisti c
    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, adLockOptimisti c
    If Not rs.EOF Then
    strdes = rs!designations id
    End If
    rs.Close
    If Trim(Form2.txtg id.Text) = "" Then
    MsgBox "Please enter numbers", vbOKOnly, "ERROR"
    cbostate.SetFoc us
    ElseIf IsNumeric(txtnm e.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.Te xt & "'", conn, adOpenStatic, adLockOptimisti c

    If rs1.EOF Then
    conn.BeginTrans
    conn.Execute "insert into EmployeeDetails (GTTLID,Employe eName,age,sex,D epartment,Desig nation,DOB,DOJ, PhoneNo,MobileN o,EmailId,Addre ss) 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
    [/code]
    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

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #3
      Originally posted by lotus18
      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.Connectio n
      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=sqlol edb.1;User ID=sa;password= ;Data Source=STATISTI CS;Initial Catalog=Nicks"
      'conn.Open "Provider=sqlol edb.1;User ID=sa;password= ;Data Source=HS445;In itial Catalog=EXMP"
      Form1.Show
      End Sub


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

      Nikhita(Nicks)

      Comment

      Working...