Vous êtes sur la page 1sur 19

Dim rs As ADODB.

Recordset

Sub cleartext() Dim pcont As Control For Each pcont In Me.Controls If TypeOf pcont Is TextBox Then pcont.Text = "" If TypeOf pcont Is ComboBox Then pcont.Text = "" Next

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select distinct earea from empmaster", con, adOpenDynamic, adLockOptimistic cmbarea.Clear Do While Not rs.EOF If rs.Fields(0) <> "" Then cmbarea.AddItem rs.Fields(0) rs.MoveNext Loop

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select distinct ecity from empmaster", con, adOpenDynamic, adLockOptimistic cmbcity.Clear Do While Not rs.EOF If rs.Fields(0) <> "" Then cmbcity.AddItem rs.Fields(0) rs.MoveNext

Loop

End Sub Public Sub setgrid() With gridsearch

.Columns(0).Width = 1000 .Columns(1).Width = 1000 .Columns(1).Caption = "Date" .Columns(2).Width = 1000 .Columns(2).Caption = "Name" .Columns(3).Width = 1000 .Columns(3).Caption = "Address1" .Columns(4).Width = 1000 .Columns(4).Caption = "Address2" .Columns(5).Width = 1000 .Columns(5).Caption = "Area" .Columns(6).Width = 1000 .Columns(6).Caption = "City" .Columns(7).Width = 1000 .Columns(7).Caption = "Basic Salary" .Columns(8).Width = 1000 .Columns(8).Caption = "Remarks"

' .Columns(9).Width = 100

End With End Sub

Private Sub cmbarea_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Private Sub cmbarea_LostFocus() Dim i As Integer a=0 If cmbarea.Text <> "" Then For i = 0 To cmbarea.ListCount - 1 If cmbarea.Text = cmbarea.List(i) Then a=1 Exit For End If

Next i If a = 0 Then MsgBox "Please Select from list Only", vbInformation cmbarea.Text = "" cmbarea.SetFocus Exit Sub

End If End If End Sub

Private Sub cmbcity_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Private Sub CmdAdd_Click() cleartext CODE_AUTO txtdate.SetFocus cmdsave.Enabled = True txtdate.Value = Date End Sub

Private Sub Cmdaddarea_Click() frmaddarea.Visible = True txtnewarea.SetFocus

End Sub

Private Sub cmdaddcity_Click() frmnewcity.Visible = True txtnewcity.SetFocus

End Sub

Private Sub cmddelete_Click() If MsgBox("Are You Sure You Want to Delete Record", vbYesNo) = vbNo Then Exit Sub Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "delete from EmpMaster where SNO =" & Val(txtsno.Text), con, adOpenDynamic, adLockOptimistic MsgBox "Record is Deleted!", vbOKOnly

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select * from EmpMaster", con, adOpenDynamic, adLockOptimistic Set gridsearch.DataSource = rs cleartext End Sub

Private Sub cmdexit_Click() Unload Me End Sub

Private Sub cmdnewarea_Click() If txtnewarea.Text <> "" Then Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient

rs.Open "Select * from Catemaster where ucase(categorytype) = 'Area' AND UCASE(CATEGORYNAME) = '" & UCase(txtnewarea.Text) & "' ", con, adOpenDynamic, adLockOptimistic If rs.RecordCount = 0 Then rs.AddNew rs.Fields("categoryname") = txtnewarea.Text rs.Fields("categorytype") = "Area" rs.Update End If

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "Select distinct categoryname from catemaster where ucase(categorytype) = 'Area'", con, adOpenDynamic, adLockOptimistic If rs.RecordCount > 0 Then cmbarea.Clear Do While Not rs.EOF If rs.Fields(0) <> "" Then cmbarea.AddItem rs.Fields(0) rs.MoveNext Loop End If 'fraArea.Visible = False cmbarea.Text = txtnewarea.Text txtnewarea = "" End If cmdnewareaclose.SetFocus End Sub

Private Sub cmdnewarea_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Private Sub cmdnewareaclose_Click() frmaddarea.Visible = False cmbcity.SetFocus End Sub

Private Sub cmdnewcity_Click() If txtnewcity.Text <> "" Then Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "Select * from Catemaster where ucase(categorytype) = 'City' AND UCASE(CATEGORYNAME) = '" & UCase(txtnewcity.Text) & "' ", con, adOpenDynamic, adLockOptimistic If rs.RecordCount = 0 Then rs.AddNew rs.Fields("categoryname") = txtnewcity.Text rs.Fields("categorytype") = "City" rs.Update End If

Set rs = New ADODB.Recordset

rs.CursorLocation = adUseClient rs.Open "Select distinct categoryname from catemaster where ucase(categorytype) = 'City'", con, adOpenDynamic, adLockOptimistic If rs.RecordCount > 0 Then cmbcity.Clear Do While Not rs.EOF If rs.Fields(0) <> "" Then cmbcity.AddItem rs.Fields(0) rs.MoveNext Loop End If cmbcity.Text = txtnewcity.Text txtnewcity.Text = "" End If

cmdnewcityclose.SetFocus End Sub

Private Sub cmdnewcityclose_Click() frmnewcity.Visible = False txtbsalary.SetFocus End Sub

Private Sub cmdsave_Click() If txtsno.Text = "" Then MsgBox "Please Click on ADD Button!" CmdAdd.SetFocus

Exit Sub End If

If txtname.Text = "" Then MsgBox "Please enter the Employee name!" txtname.SetFocus Exit Sub End If

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select * from EmpMaster", con, adOpenDynamic, adLockOptimistic rs.Find ("SNO = '" & txtsno.Text & "'") If rs.EOF = True Then rs.AddNew Else If MsgBox("Record Exist ! Overwrite?", vbYesNo + vbQuestion) = vbNo Then Exit Sub End If If txtsno.Text <> "" Then rs.Fields("Sno") = txtsno.Text Else rs.Fields("sno") = "" rs.Fields("edate") = txtdate.Value If txtname.Text <> "" Then rs.Fields("ename") = txtname.Text Else rs.Fields("ename") = "" If txtadd1.Text <> "" Then rs.Fields("eadd1") = txtadd1.Text If txtadd2.Text <> "" Then rs.Fields("eadd2") = txtadd2.Text If cmbarea.Text <> "" Then rs.Fields("earea") = cmbarea.Text

If cmbcity.Text <> "" Then rs.Fields("ecity") = cmbcity.Text If txtbsalary.Text <> "" Then rs.Fields("ebsalary") = txtbsalary.Text If txtremarks.Text <> "" Then rs.Fields("eremarks") = txtremarks.Text rs.Update MsgBox "Record is Saved!"

Call cleartext cmdsave.Enabled = False Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "SELECT * FROM EmpMaster", con, adOpenDynamic, adLockOptimistic Set gridsearch.DataSource = rs End Sub

Private Sub cmdsave_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{TAB}" End Sub

Private Sub Command1_Click() frmregister.Show End Sub

Private Sub Form_Load() con_open txtdate.Value = Date

txtsearchdate.Value = Date

CmdAdd.TabIndex = 0 txtsno.TabIndex = 1 txtdate.TabIndex = 2 txtname.TabIndex = 3 txtadd1.TabIndex = 4 txtadd2.TabIndex = 5 cmbarea.TabIndex = 6 cmbcity.TabIndex = 7 txtbsalary.TabIndex = 8 txtremarks.TabIndex = 9

cmdsave.TabIndex = 10 cmdexit.TabIndex = 11 cmddelete.TabIndex = 12

txtsearchname.TabIndex = 13 txtsearchdate.TabIndex = 14

frmaddarea.Visible = False frmnewcity.Visible = False

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient

rs.Open "SELECT * FROM EmpMaster", con, adOpenDynamic, adLockOptimistic Set gridsearch.DataSource = rs

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select distinct earea from empmaster", con, adOpenDynamic, adLockOptimistic cmbarea.Clear Do While Not rs.EOF If rs.Fields(0) <> "" Then cmbarea.AddItem rs.Fields(0) rs.MoveNext Loop

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select distinct ecity from empmaster", con, adOpenDynamic, adLockOptimistic cmbcity.Clear Do While Not rs.EOF If rs.Fields(0) <> "" Then cmbcity.AddItem rs.Fields(0) rs.MoveNext Loop Call setgrid End Sub

Private Sub gridsearch_DblClick()

cmddelete.Enabled = True

Dim rsfill As ADODB.Recordset Set rsfill = New ADODB.Recordset rsfill.CursorLocation = adUseClient rsfill.Open "select * from Empmaster where [Sno] = " & Val(gridsearch.Columns(0)) & " ORDER BY SNO", con, adOpenDynamic, adLockOptimistic

If rsfill.RecordCount > 0 Then If rsfill.BOF = False Then rsfill.MoveFirst If rsfill.Fields("SNO") <> "" Then txtsno.Text = rsfill.Fields("SNO") Else txtsno.Text = 0 If rsfill.Fields("edate") <> "" Then txtdate.Value = rsfill.Fields("edate") If rsfill.Fields("ename") <> "" Then txtname.Text = rsfill.Fields("ename") Else txtname.Text = "" If rsfill.Fields("eadd1") <> "" Then txtadd1.Text = rsfill.Fields("eadd1") Else txtadd1.Text = "" If rsfill.Fields("eadd2") <> "" Then txtadd2.Text = rsfill.Fields("eadd2") Else txtadd2.Text = "" If rsfill.Fields("earea") <> "" Then cmbarea.Text = rsfill.Fields("earea") Else cmbarea.Text = "" If rsfill.Fields("ecity") <> "" Then cmbcity.Text = rsfill.Fields("ecity") Else cmbcity.Text = "" If rsfill.Fields("ebsalary") <> "" Then txtbsalary.Text = rsfill.Fields("ebsalary") Else txtbsalary.Text = "" If rsfill.Fields("eremarks") <> "" Then txtremarks.Text = rsfill.Fields("eremarks") Else txtremarks.Text = "" rsfill.MoveNext 'txtename.SetFocus End If

cmdsave.Enabled = True End Sub

Private Sub gridsearch_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyUp Then If gridsearch.Bookmark = gridsearch.RowBookmark(0) Then txtsearchname.SetFocus End If End If If KeyCode = 13 Then If gridsearch.ApproxCount > 0 Then gridsearch_DblClick End If End If End Sub

Private Sub txtadd1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Private Sub txtadd2_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Private Sub txtbsalary_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}"

End Sub

Private Sub txtdate_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{TAB}" End Sub

Private Sub txtname_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}"

End Sub

Private Sub txtnewarea_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub Private Sub txtnewcity_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Private Sub txtremarks_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 And txtremarks.Text = "" Then cmdsave.SetFocus

End Sub

Private Sub txtsearchdate_Change() Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select * from EmpMaster where [eDate] = cdate('" & txtsearchdate.Value & "')", con, adOpenDynamic, adLockOptimistic Set gridsearch.DataSource = rs setgrid End Sub

Private Sub txtsearchname_Change() Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select * from EmpMaster where ucase(eName) like '" & UCase(txtsearchname.Text) & "%'", con, adOpenDynamic, adLockOptimistic Set gridsearch.DataSource = rs setgrid End Sub

Private Sub txtsearchname_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyReturn Then gridsearch_DblClick End If

If KeyCode = vbKeyDown Then If gridsearch.ApproxCount > 0 Then gridsearch.SetFocus End If

End Sub

Private Sub txtSno_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys "{tab}" End Sub

Public Sub CODE_AUTO() Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open "select max(val(sno)) from empmaster", con, adOpenDynamic, adLockOptimistic If rs.Fields(0) <> "" Then txtsno.Text = rs.Fields(0) + 1 Else txtsno.Text = 1 End Sub