[code=vb]
Private Sub cmdAdd_Click()
txtid.Enabled = True
If txtid.Text = " " Then
MsgBox "Enter the id,Please!!!", vbOKOnly, "PAYROLL"
txtid.SetFocus
With txtid
.SelStart = 0
'.SelLength = Len(txtid.Text)
.SetFocus
End With
Exit Sub
ElseIf txtname.Text = " " Then
MsgBox "Enter the name,Please!!!" , vbOKOnly, "PAYROLL"
'txtname.SetFoc us
Exit Sub
With txtname
.SelStart = 0
' .SelLength = Len(txtname.Tex t)
.SetFocus
End With
'End If
ElseIf txtwhr.Text = " " Then
MsgBox "Enter the working hours,Please!!! ", vbOKOnly, "PAYROLL"
txtwhr.SetFocus
Exit Sub
With txtwhr
.SelStart = 0
'.SelLength = Len(txtwhr.Text )
.SetFocus
End With
ElseIf Form1.txtrate.T ext = " " Then
MsgBox "Enter the rate,Please!!!" , vbOKOnly, "PAYROLL"
txtrate.SetFocu s
Exit Sub
With txtrate
.SelStart = 0
.SetFocus
End With
ElseIf txtorate.Text = " " Then
MsgBox "Enter the Overtime Rate,Please!!!" , vbOKOnly, "PAYROLL"
txtorate.SetFoc us
Exit Sub
With txtorate
.SelStart = 0
.SetFocus
End With
Else
rs.Open "select * from empdetail Where ID='" & txtid.Text & "'", conn, adOpenStatic, adLockOptimisti c
If rs.EOF Then
conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
Else
MsgBox "Duplicate Entry"
End If
rs.Close
Set rs = Nothing
ListView1.ListI tems.Clear
addcol
Form1.txtid.Tex t = ""
Form1.txtname.T ext = ""
Form1.txtwhr.Te xt = ""
Form1.txtrate.T ext = ""
Form1.txtorate. Text = ""
End If
End Sub
Private Sub cmdBack_Click()
Form1.txtid.Tex t = ""
Form1.txtname.T ext = ""
Form1.txtwhr.Te xt = ""
Form1.txtrate.T ext = ""
Form1.txtorate. Text = ""
Form1.Hide
MDIForm1.Show
End Sub[/code]
This above code is for adding four fields to databse where id the primary kiey.Please go through because,its works for once,ie when one data gets inserted,u dont have any pblm.But whenthe computation is done for the second time without closing the window,an error occurs!!!
Please Go through........ ...!!!!!~
Where I HAve go wrong????
Private Sub cmdAdd_Click()
txtid.Enabled = True
If txtid.Text = " " Then
MsgBox "Enter the id,Please!!!", vbOKOnly, "PAYROLL"
txtid.SetFocus
With txtid
.SelStart = 0
'.SelLength = Len(txtid.Text)
.SetFocus
End With
Exit Sub
ElseIf txtname.Text = " " Then
MsgBox "Enter the name,Please!!!" , vbOKOnly, "PAYROLL"
'txtname.SetFoc us
Exit Sub
With txtname
.SelStart = 0
' .SelLength = Len(txtname.Tex t)
.SetFocus
End With
'End If
ElseIf txtwhr.Text = " " Then
MsgBox "Enter the working hours,Please!!! ", vbOKOnly, "PAYROLL"
txtwhr.SetFocus
Exit Sub
With txtwhr
.SelStart = 0
'.SelLength = Len(txtwhr.Text )
.SetFocus
End With
ElseIf Form1.txtrate.T ext = " " Then
MsgBox "Enter the rate,Please!!!" , vbOKOnly, "PAYROLL"
txtrate.SetFocu s
Exit Sub
With txtrate
.SelStart = 0
.SetFocus
End With
ElseIf txtorate.Text = " " Then
MsgBox "Enter the Overtime Rate,Please!!!" , vbOKOnly, "PAYROLL"
txtorate.SetFoc us
Exit Sub
With txtorate
.SelStart = 0
.SetFocus
End With
Else
rs.Open "select * from empdetail Where ID='" & txtid.Text & "'", conn, adOpenStatic, adLockOptimisti c
If rs.EOF Then
conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
Else
MsgBox "Duplicate Entry"
End If
rs.Close
Set rs = Nothing
ListView1.ListI tems.Clear
addcol
Form1.txtid.Tex t = ""
Form1.txtname.T ext = ""
Form1.txtwhr.Te xt = ""
Form1.txtrate.T ext = ""
Form1.txtorate. Text = ""
End If
End Sub
Private Sub cmdBack_Click()
Form1.txtid.Tex t = ""
Form1.txtname.T ext = ""
Form1.txtwhr.Te xt = ""
Form1.txtrate.T ext = ""
Form1.txtorate. Text = ""
Form1.Hide
MDIForm1.Show
End Sub[/code]
This above code is for adding four fields to databse where id the primary kiey.Please go through because,its works for once,ie when one data gets inserted,u dont have any pblm.But whenthe computation is done for the second time without closing the window,an error occurs!!!
Please Go through........ ...!!!!!~
Where I HAve go wrong????
Comment