Solved

What's Wrong in my code

Posted on 2009-04-03
4
166 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now