Advertisement
Guest User

Untitled

a guest
May 15th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. Dim conn As ADODB.Connection
  2. Dim admin As ADODB.Recordset
  3. Dim adm As String
  4. Dim addnew As Boolean
  5. Private Sub Command1_Click()
  6. addnew = True
  7. Command1.Enabled = False
  8. Text1.Locked = False
  9. Text2.Locked = False
  10. Text3.Locked = False
  11. Text4.Locked = False
  12. Text5.Locked = False
  13. Text6.Locked = False
  14. Text1.Text = ""
  15. Text2.Text = ""
  16. Text3.Text = ""
  17. Text4.Text = ""
  18. Text5.Text = ""
  19. Text6.Text = ""
  20. End Sub
  21.  
  22. Private Sub Command2_Click()
  23. conn.Execute "delete from employeesrecord where EmpID='" & Text1.Text & "'"
  24. showgrid
  25. showdata
  26. End Sub
  27. Private Sub showgrid()
  28. Set admin = New ADODB.Recordset
  29. admin.CursorLocation = adUseClient
  30. adm = "select * from employeesrecord"
  31. admin.Open adm, conn, adoOpenDynamic, adLockBatchOptimistic
  32. Set DataGrid1.DataSource = admin
  33. DataGrid1.Refresh
  34. End Sub
  35. Private Sub Command3_Click()
  36. Command3.Enabled = False
  37. conn.Execute "insert into employeesrecord (EmpID, F_name, L_name, Address, City, Phone) values ('" & Text1.Text & "', '" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "','" & Text6.Text & "')"
  38. Set admin = New ADODB.Recordset
  39. admin.CursorLocation = adUseClient
  40. adm = "select * from employeesrecord"
  41. admin.Open adm, conn, adoOpenDynamic, adLockBatchOptimistic
  42. Set DataGrid1.DataSource = admin
  43. DataGrid1.Refresh
  44. Command1.Enabled = True
  45. showgrid
  46. showdata
  47. Text1.Locked = True
  48. Text2.Locked = True
  49. Text3.Locked = True
  50. Text4.Locked = True
  51. Text5.Locked = True
  52. Text6.Locked = True
  53. End Sub
  54. Private Sub Command4_Click()
  55. showgrid
  56. showdata
  57. Text1.Locked = True
  58. Text2.Locked = True
  59. Text3.Locked = True
  60. Text4.Locked = True
  61. Text5.Locked = True
  62. Text6.Locked = True
  63. End Sub
  64.  
  65. Private Sub Command5_Click()
  66. Unload Me
  67. Menu.Show
  68. End Sub
  69.  
  70. Private Sub DataGrid1_Click()
  71. Text1.Text = DataGrid1.Columns(0)
  72. Text2.Text = DataGrid1.Columns(1)
  73. Text3.Text = DataGrid1.Columns(2)
  74. Text4.Text = DataGrid1.Columns(3)
  75. Text5.Text = DataGrid1.Columns(4)
  76. Text6.Text = DataGrid1.Columns(5)
  77. End Sub
  78. Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
  79. KeyAscii = 0
  80. End Sub
  81. Private Sub Form_Load()
  82. connserver
  83. Set admin = New ADODB.Recordset
  84. admin.CursorLocation = adUseClient
  85. adm = "select * from employeesrecord"
  86. admin.Open adm, conn, adoOpenDynamic, adLockBatchOptimistic
  87. Set DataGrid1.DataSource = admin
  88. DataGrid1.Refresh
  89. showgrid
  90. showdata
  91. End Sub
  92. Private Sub showdata()
  93. On Error GoTo a
  94. Text1.Text = admin!EmpID
  95. Text2.Text = admin!F_name
  96. Text3.Text = admin!L_name
  97. Text4.Text = admin!Address
  98. Text5.Text = admin!City
  99. Text6.Text = admin!Phone
  100. Exit Sub
  101. a:
  102. Text1.Text = ""
  103. Text2.Text = ""
  104. Text3.Text = ""
  105. Text4.Text = ""
  106. Text5.Text = ""
  107. Text6.Text = ""
  108. End Sub
  109. Private Sub connserver()
  110. Set conn = New ADODB.Connection
  111. conn.Open "Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=alps;USER=root;PASSWORD=;OPTION=3"
  112. Set admin = New ADODB.Recordset
  113. End Sub
  114.  
  115.  
  116. Private Sub Text1_Change()
  117. chk
  118. End Sub
  119. Private Sub Text1_KeyPress(KeyAscii As Integer)
  120. Select Case KeyAscii
  121. Case Asc(vbCr)
  122. KeyAscii = 0
  123. Case 8, 46
  124. Case 47 To 58
  125. Case Else
  126. KeyAscii = 0
  127. End Select
  128. End Sub
  129.  
  130. Private Sub Text2_Change()
  131. chk
  132. End Sub
  133. Private Sub Text3_Change()
  134. chk
  135. End Sub
  136. Private Sub Text4_Change()
  137. chk
  138. End Sub
  139. Private Sub Text5_Change()
  140. chk
  141. End Sub
  142. Private Sub Text6_Change()
  143. chk
  144. End Sub
  145. Private Sub chk()
  146. If addnew = True Then
  147. If Len(Text1.Text) = 0 Or Len(Text2.Text) = 0 Or Len(Text3.Text) = 0 Or Len(Text4.Text) = 0 Or Len(Text5.Text) = 0 Or Len(Text6.Text) = 0 Then
  148. Command3.Enabled = False
  149. Else
  150. Command3.Enabled = True
  151. End If
  152. End If
  153. End Sub
  154. Private Sub Text6_KeyPress(KeyAscii As Integer)
  155. Select Case KeyAscii
  156. Case Asc(vbCr)
  157. KeyAscii = 0
  158. Case 8, 46
  159. Case 47 To 58
  160. Case Else
  161. KeyAscii = 0
  162. End Select
  163. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement