Solved

What's Wrong in my code

Posted on 2009-04-03
4
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 71
A macro to Count the number of rows across all worksheets 3 149
how to Classify of email (pdf attachments) 7 50
Problem to line 23 73
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

740 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