guys mao ni aqng code libug man q unsaon ang code sa delete all recorde sa database, 1 click lang xa erase daun.
vb 6 xa boss. salamat sa mka tabang. .
pls guys
Private Sub Add_Click()
Frame1.Visible = True
txtint.Text = ""
txtid.Text = ""
txttotalbet.Text = ""
txttotal.Text = ""
txtnegative.Text = ""
Frame2.Visible = False
txtnum.SetFocus
Dim rss As Recordset
Set rss = New Recordset
Dim cnn As Connection
Set cnn = New Connection
cnn.CursorLocation = adUseClient
cnn.Open GetConnectionString
rss.Open "Select * from tbltest", cnn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rss
End Sub
Private Sub cmdclick2_Click()
If txttotalbet.Text = "" And txtnegative.Text = "" Then
MsgBox "Invalid Input", vbExclamation, "Error"
Else
txttotal.Text = Val(txttotalbet.Text) - Val(txtnegative.Text)
End If
End Sub
Private Sub cmdok_Click()
Dim rs As Recordset
Dim cnn As Connection
Set cnn = New Connection
cnn.CursorLocation = adUseClient
cnn.Open GetConnectionString
Dim prev As Currency
Dim total As Currency
Dim itotal As Currency
Dim t1 As Currency
Dim t2 As Currency
Dim t3 As Currency
If txtnum.Text = "" Then
MsgBox "Invalid Input", vbExclamation, ""
txtnum.SetFocus
ElseIf Len(txtnum.Text) < 3 Then
MsgBox "Invalid Input", vbExclamation, ""
txtnum.SetFocus
ElseIf Val(txtnum.MaxLength) <= 2 Then
MsgBox "Invalid Input", vbExclamation, ""
txtnum.SetFocus
ElseIf txtbet.Text = "" Then
MsgBox "Invalid Input", vbExclamation, ""
txtbet.SetFocus
ElseIf txtbet.Text <= 0 Then
MsgBox "Invalid Input", vbExclamation, ""
txtbet.SetFocus
ElseIf txtlimit.Text = "" Then
MsgBox "Invalid Input", vbExclamation, ""
txtlimit.SetFocus
ElseIf txtlimit.Text <= 0 Then
MsgBox "Invalid Input", vbExclamation, ""
txtlimit.SetFocus
Else
Set rs = New Recordset
rs.Open "select * from tbltest where ID_Num='" & frmmain.txtnum.Text & "'", cnn, adOpenDynamic, adLockBatchOptimistic
If rs.EOF Then
rs.AddNew
rs.Fields("ID_Num") = txtnum.Text
rs.Fields("Bet") = txtbet.Text
rs.Fields("Limit") = txtlimit.Text
rs.Fields("iTotal") = Val(txtbet.Text) - Val(txtlimit.Text)
rs.Update
rs.UpdateBatch
Else
itotal = rs.Fields("Bet")
t1 = rs.Fields("Limit")
t2 = rs.Fields("iTotal")
total = txtbet.Text
total = itotal + total
rs.Fields("Bet") = total
t3 = total - t1
rs.Fields("iTotal") = t3
rs.Update
rs.UpdateBatch
End If
End If
Dim rss As Recordset
Set rss = New Recordset
rss.Open "Select * from tbltest", cnn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rss
txtnum.Text = ""
txtbet.Text = ""
txtnum.SetFocus
End Sub
Private Sub Command1_Click()
On Error GoTo Procerror
Dim cnn As Connection
Set cnn = New Connection
cnn.CursorLocation = adUseClient
cnn.Open GetConnectionString
Dim rs As Recordset
Set rs = New Recordset
rs.Open "Select sum(iTotal)as bettotal from tbltest", cnn, adOpenDynamic, adLockBatchOptimistic
txtztotal.Text = rs!bettotal
Procexit:
Exit Sub
Procerror:
MsgBox "No Records Found", vbExclamation, "Empty Fields"
txtztotal.Text = ""
Resume Procexit
End Sub
Private Sub Command2_Click()
' diri kay button inig click mu erase tnan data sa database, 1 click lang bah
End Sub
Private Sub DataGrid1_DblClick()
On Error GoTo Procerror
Dim cnn As Connection
Set cnn = New Connection
cnn.CursorLocation = adUseClient
cnn.Open GetConnectionString
Dim rs As Recordset
Set rs = New Recordset
rs.Open "Delete * from tbltest where ID_Num= '" & DataGrid1.Columns(0) & "'", cnn, adOpenDynamic, adLockBatchOptimistic
Set rs = New Recordset
rs.Open "Select * from tbltest", cnn, adOpenDynamic, adLockBatchOptimistic
DataGrid1.ClearFields
DataGrid1.Refresh
Set DataGrid1.DataSource = rs
Procexit:
Exit Sub
Procerror:
MsgBox "Empty Field", vbExclamation, ""
Resume Procexit
End Sub
Private Sub Form_Activate()
Dim rss As Recordset
Dim rs As Recordset
Set rs = New Recordset
Set rss = New Recordset
Dim cnn As Connection
Set cnn = New Connection
cnn.CursorLocation = adUseClient
cnn.Open GetConnectionString
rss.Open "Select * from tbltest", cnn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rss
End Sub
Private Sub Subtract_Click()
Frame2.Visible = True
txtnum.Text = ""
txtbet.Text = ""
Frame1.Visible = False
txtint.SetFocus
End Sub
Private Sub sub_Click()
Frame2.Visible = True
txtnum.Text = ""
txtbet.Text = ""
Frame1.Visible = False
txtint.SetFocus
End Sub
Private Sub txtbet_KeyPress(KeyAscii As Integer)
Dim strvalid
strvalid = "1234567890"
If KeyAscii > 26 Then
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
If KeyAscii = vbKeyReturn Then
cmdok.SetFocus
End If
End Sub
Private Sub txtint_KeyPress(KeyAscii As Integer)
Dim cnn As Connection
Set cnn = New Connection
cnn.CursorLocation = adUseClient
cnn.Open GetConnectionString
Dim rss As Recordset
Dim strvalid
strvalid = "1234567890"
If KeyAscii > 26 Then
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
If KeyAscii = vbKeyReturn Then
If Len(txtint.Text) < 3 Then
MsgBox "Invalid Input", vbExclamation, "Error"
txtint.SetFocus
Else
On Error GoTo Procerror
Set rss = New Recordset
rss.Open "Select Bet from tbltest where ID_Num='" & txtint.Text & "'", cnn, adOpenDynamic, adLockBatchOptimistic
txttotalbet.Text = rss!Bet
txtid.Text = txtint.Text
txtint.Text = ""
txtnegative.SetFocus
Procexit:
Exit Sub
Procerror:
MsgBox "Empty Field", vbExclamation, ""
Resume Procexit
End If
End If
End Sub
Private Sub txtlimit_KeyPress(KeyAscii As Integer)
Dim strvalid
strvalid = "1234567890"
If KeyAscii > 26 Then
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
If KeyAscii = vbKeyReturn Then
cmdok.SetFocus
End If
End Sub
Private Sub txtnegative_KeyPress(KeyAscii As Integer)
Dim strvalid
strvalid = "1234567890"
If KeyAscii > 26 Then
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
If KeyAscii = vbKeyReturn Then
If txtnegative.Text = "" Then
MsgBox "Invalid Input", vbExclamation, "Error"
txtnegative.SetFocus
ElseIf txtnegative.Text <= 0 Then
MsgBox "Invalid Input", vbExclamation, "Error"
txtnegative.SetFocus
Else
cmdclick2.SetFocus
End If
End If
End Sub
Private Sub txtnum_KeyPress(KeyAscii As Integer)
Dim strvalid
strvalid = "1234567890"
If KeyAscii > 26 Then
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
If KeyAscii = vbKeyReturn Then
txtbet.SetFocus
End If
End Sub