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:
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:
Comment