Solved

What's Wrong in my code

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

14 Experts available now in Live!

Get 1:1 Help Now