Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Private Sub CCS()

On Error GoTo errHandler:

Dim Total As Double

Dim Total2 As Double

Total = 0

If Len(tbx4.Value) > 0 Then Total = Total + CDbl(tbx4.Value)

If Len(tbx5.Value) > 0 Then Total = Total + CDbl(tbx5.Value)

If Len(tbx6.Value) > 0 Then Total = Total + CDbl(tbx6.Value)

If Len(tbx7.Value) > 0 Then Total = Total + CDbl(tbx7.Value)

If Len(tbx8.Value) > 0 Then Total = Total + CDbl(tbx8.Value)

If Len(tbx9.Value) > 0 Then Total = Total + CDbl(tbx9.Value)

If Len(tbx10.Value) > 0 Then Total = Total + CDbl(tbx10.Value)

If Len(tbx11.Value) > 0 Then Total = Total + CDbl(tbx11.Value)

If Len(tbx12.Value) > 0 Then Total = Total + CDbl(tbx12.Value)

If Len(tbx13.Value) > 0 Then Total = Total + CDbl(tbx13.Value)

If Len(tbx14.Value) > 0 Then Total = Total + CDbl(tbx14.Value)

If Len(tbx15.Value) > 0 Then Total = Total + CDbl(tbx15.Value)

If Len(tbx16.Value) > 0 Then Total = Total + CDbl(tbx16.Value)

If Len(tbx18.Value) > 0 Then Total = Total + CDbl(tbx18.Value)

If Len(txtbx5.Value) > 0 Then Total2 = CDbl(txtbx5.Value)

totamnt.Caption = Total

If tbx4.Value & tbx5.Value & tbx6.Value & tbx7.Value & tbx8.Value & _

tbx9.Value & tbx10.Value & tbx11.Value & tbx12.Value & tbx13.Value & _

tbx14.Value & tbx15.Value & tbx16.Value & tbx18.Value = "" Then

totamnt.Caption = ""

Else

totamnt = Format(totamnt, "#,###.00")


End If

If totamnt.Caption = 0 Then

totamnt.Caption = ""

Else

totamnt = Format(totamnt, "#,###.00")

End If

On Error GoTo 0

Exit Sub

errHandler:

Me.tbx7.Value = ""

End Sub
Private Sub Add_Click()

Dim cnn As ADODB.Connection 'dim the ADO collection class

Dim rst As ADODB.Recordset 'dim the ADO recordset class

Dim dbPath

Dim x As Long, i As Long

If tbx1.Value & totamnt.Caption & tbx2.Value & tbx3.Value = "" Then

MsgBox ("Please Insert Data"), vbInformation

ElseIf tbx1.Value = "" Then

MsgBox ("Please Insert Date"), vbInformation

Else

'Error handler

On Error GoTo errHandler:

dbPath = "C:\Users\CDL\Documents\CRMSv5.accdb"

Set cnn = New ADODB.Connection

cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath

Set rst = New ADODB.Recordset

rst.Open Source:="CCS", ActiveConnection:=cnn, _

CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _

Options:=adCmdTable

'you now have the recordset object

With rst

.AddNew

.Fields("Period_Covered").Value = tbx1

.Fields("OR_No/Ref").Value = (IIf(Me.tbx2.Value = "", 0, Me.tbx2.Value))

.Fields("Payor/Office_Collector").Value = (IIf(Me.tbx3.Value = "", 0, Me.tbx3.Value))


.Fields("Total_Collections").Value = totamnt.Caption

.Fields("SC_Discount").Value = (IIf(Me.tbx7.Value = "", 0, Me.tbx7.Value))

.Fields("Collections_A/R").Value = (IIf(Me.tbx4.Value = "", 0, Me.tbx4.Value) + 0) + _

(IIf(Me.tbx5.Value = "", 0, Me.tbx5.Value) + 0) + _

(IIf(Me.tbx6.Value = "", 0, Me.tbx6.Value) + 0)

.Fields("Fines_and_Penalties").Value = (IIf(Me.tbx8.Value = "", 0, Me.tbx8.Value) + 0) + _

(IIf(Me.tbx9.Value = "", 0, Me.tbx9.Value) + 0)

.Fields("Guaranty_Deposits").Value = (IIf(Me.tbx10.Value = "", 0, Me.tbx10.Value))

.Fields("Other_Service_Income").Value = (IIf(Me.tbx11.Value = "", 0, Me.tbx11.Value))

.Fields("Other_Receivables").Value = (IIf(Me.tbx12.Value = "", 0, Me.tbx12.Value))

.Fields("Miscellaneous_Income").Value = (IIf(Me.tbx13.Value = "", 0, Me.tbx13.Value))

.Fields("Current").Value = (IIf(Me.tbx4.Value = "", 0, Me.tbx4.Value))

.Fields("CY_Arrears").Value = (IIf(Me.tbx5.Value = "", 0, Me.tbx5.Value))

.Fields("PY_Arrears").Value = (IIf(Me.tbx6.Value = "", 0, Me.tbx6.Value))

.Fields("CY_Pen").Value = (IIf(Me.tbx8.Value = "", 0, Me.tbx8.Value))

.Fields("PY_Pen").Value = (IIf(Me.tbx9.Value = "", 0, Me.tbx9.Value))

' If cbx.Value = True Then

'

' If tbx17.Value = "Other Deferred Credits" Then

' .Fields("Other_Deferred_Credits").Value = (IIf(Me.tbx18.Value = "", 0, Me.tbx18.Value))

' ElseIf tbx17.Value = "Due from Officers and Employees" Then

' .Fields("Due_from_Officers_and_Employees").Value = (IIf(Me.tbx18.Value = "", 0,


Me.tbx18.Value))

' Else

' .Fields("Other_Account_Name").Value = tbx17

' .Fields("Other_Receipts").Value = (IIf(Me.tbx18.Value = "", 0, Me.tbx18.Value))

' End If

' Else
' .Fields("Other_Account_Name").Value = ""

' .Fields("Other_Receipts").Value = 0

' End If

If tbx3.Value = "Felipina L. Soriano" Then

.Fields("Reference_Code").Value = "1" & Format(Now, "mmddyyhhmm") & Format(Now,"hhmm")

ElseIf tbx3.Value = "Marie Antonette G. Aclan" Then

.Fields("Reference_Code").Value = "2" & Format(Now, "mmddyyhhmm") & Format(Now,"hhmm")

ElseIf tbx3.Value = "Annabelle V. Ferrer" Then

.Fields("Reference_Code").Value = "3" & Format(Now, "mmddyyhhmm") & Format(Now,"hhmm")

ElseIf tbx3.Value <> "Felipina L. Soriano" Or tbx3.Value <> "Marie Antonette G. Aclan" Or _

tbx3.Value <> "Annabelle V. Ferrer" Then

.Fields("Reference_Code").Value = "4" & Format(Now, "mmddyyhhmm") & Format(Now,"hhmm")

End If

.Update

End With

' Close the connection

rst.Close

cnn.Close

Set rst = Nothing

Set cnn = Nothing

srchbx.Value = tbx1.Value

import

'communicate with the user


MsgBox "The data has been successfully sent to the access database"

For x = 1 To 13

Me.Controls("tbx" & x).Value = ""

Next

tbx1.SetFocus

On Error GoTo 0

Exit Sub

errHandler:

Set rst = Nothing

Set cnn = Nothing

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAdd"

End If

End Sub

You might also like