• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

What's Wrong in my code

What's wrong about this code?
!The_Total = IsNull(!The_Total) + Trim(lblDueAmount.Caption)
Public Sub save_Table(cn As ADODB.Connection, lpTable_No As String, Customer_name As String, Time_in As String, Time_Out As String, The_Total As String)
Dim rs As ADODB.Recordset
Dim sql As String
Set rs = New ADODB.Recordset
    sql = "select * from The_Table where Table_No='" & lpTable_No & "'"
    rs.LockType = adLockOptimistic
    rs.CursorType = adOpenKeyset
    rs.Open sql, cn
    With rs
        If .BOF = True And _
            .EOF = True Then
            !Table_No = lpTable_No
        End If
        !Customer_name = Trim(grid.TextMatrix(grid.Row, 0))
        !Time_in = Trim(grid.TextMatrix(grid.Row, 1))
        !Time_Out = grid.TextMatrix(grid.Row, 5)
        !The_Total = IsNull(!The_Total) + Trim(lblDueAmount.Caption)
    End With
    Set rs = Nothing
End Sub

Open in new window

Whing Dela Cruz
Whing Dela Cruz
  • 3
1 Solution
try this:

if IsNull(!The_Total) Then
    !The_Total = CDbl(Trim(lblDueAmount.Caption))
    !The_Total = !The_Total + CDbl(Trim(lblDueAmount.Caption))
End If
or this:

!The_Total=IIF(IsNull(!The_Total), 0, !The_Total) + CDbl(Trim(lblDueAmount.Caption))

Open in new window

Whing Dela CruzAuthor Commented:
thank you so much, The code is working but can you tell what is IIF?

IIF is a conditional statement.  If the first statement is evaluated to true, then the true output is sent, otherwise the false part is.

IIF(statement, true output, false output)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now