Solved

What's Wrong in my code

Posted on 2009-04-03
4
167 Views
Last Modified: 2012-05-06
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
            .AddNew
            !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)
        .Update
        .Close
    End With
    Set rs = Nothing
End Sub

Open in new window

0
Comment
Question by:Whing Dela Cruz
  • 3
4 Comments
 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24065983
try this:

if IsNull(!The_Total) Then
    !The_Total = CDbl(Trim(lblDueAmount.Caption))
Else
    !The_Total = !The_Total + CDbl(Trim(lblDueAmount.Caption))
End If
0
 
LVL 5

Accepted Solution

by:
mrcoolcoder earned 500 total points
ID: 24065987
or this:

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

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 24066051
Hi!
thank you so much, The code is working but can you tell what is IIF?

0
 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24068014
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)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 82
Notepad++ how to remove delimiter : from beggning of the line? 3 110
How to make an ADE file by code? 11 94
MsgBox 4 68
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question