Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 39
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Don't repeat code.
    Any time you do that the logic is off.

    Think about what you need to do.?

    It's a deposit, so you want to insert the credit.?

    Then if the IF is true you want to carry out the second Insert.



    This is basic logic here?

  2. #17
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Quote Originally Posted by d9pierce1 View Post
    Can I write the code as this?

    Code:
    Private Sub CmdSubmit_Click()
    
    
    Dim strSql As String
    Dim db As DAO.Database
    Set db = CurrentDb
       
        Me.TxtTransNumber = [TxtRandom]
    
    
        Select Case Me.TxtTransNumber
    
    
        Case "Deposit"
        
            If Me.ChkDepositRemburseExp = False Then
            
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                         "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
            Else
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                         "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                         "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  " & TxtTransDescription & " , '" & TxtMethod & "' , " & TxtTransAmount & ")"
    
    
            End If
    
    
        Case "Transfer", "Payment"
    
    
        Case "Purchase"
    
    
        Case "Record Bill"
    
    
        Case Else
    
    
        End Select
        
        db.Execute strSql, dbFailOnError
        
        Set db = Nothing
        
      End Sub
    you would need to move the "db.Execute strSql, dbFailOnError" from the bottom of the procedure and insert it after each strSql statement.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #18
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    "IN THIS FIRST CONDITION I WANT IT TO INSERT AS LONG AS ITS A DEPOSIT, AND THE SECOND CONDITION TO INSERT IF TRUE"
    My wife can shout at me because I let her think she's the boss.
    Not going to take it from you though. Ciao.

  4. #19
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    No, It actually credits one account in the first condition and if the "If Statement" = True, then it debits a different account. Its a double entry system. So if I deposit into an income account, and its for a Rem Exp, It Credits my income account and debits my remburseable account. The same thing for a "Purchase" sort of, if i purchase something that is rembursable, then under purchase, it would take out of one account as a debit, and if True, credit the Rembursed Expense Account.

  5. #20
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    LOL, wasnt shouting my friend, just wanted to make it so it stood out!

  6. #21
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Yep, thats what i hope to do

  7. #22
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I will try to see if i can do that accruately as "All of the Cases, actually do something different as far as credit and debit and there are two If Statments that are each different in themselves.
    Wow, I knew it was going to be a battle but somehow will suceed!
    Thanks again everyone for all the help

  8. #23
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Take one step at a time.
    Get one case working and then move on to another. As you process the next one in tuen it should get more familiar to you.

    Whenever you have a large problem, break it down to smaller steps. A lot of the time you will then see where some steps are common to all conditions?

    Ignore my comment about duplicating code, that is probably a bit to much to expect at this stage.? If you have to duplicate it as above so you can understand it,do so.

  9. #24
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Do you mean like this? As far as the "db.Execute strSql, dbFailOnError"
    Code:
    
    
    Code:
    Private Sub CmdSubmit_Click()
    
    
    Dim strSql As String
    Dim db As DAO.Database
    Set db = CurrentDb
       
        Me.TxtTransNumber = [TxtRandom]
    
    
        Select Case Me.TxtTransNumber
    
    
        Case "Deposit"
        
            If Me.ChkDepositRemburseExp = False Then
            
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                         "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
    	
     	Else
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                         "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
    	    strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                         "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  " & TxtTransDescription & " , '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
            End If
    
    
        Case "Transfer", "Payment
    
    
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                          "VALUES (" & TxtTransID & ", " & CboFromAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " To " & CboToAccount.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
                strSql =  "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                           "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboFromAccount.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
    	    db.Execute strSql, dbFailOnError
    
    
        Case "Purchase"
    
    
            If Me.ChkIsRemburseExp = False Then
            
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                                     "VALUES (" & TxtTransID & ", " & CboFromAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
    	     db.Execute strSql, dbFailOnError
     	Else
                strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                                     "VALUES (" & TxtTransID & ", " & CboFromAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
    	    strSql = "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                                         "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  " & TxtTransDescription & " , '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
            End If
    
    
        Case "Record Bill"
                strSql "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                                         "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                db.Execute strSql, dbFailOnError
    
    
    
    
        Case Else
    
    
        End Select
       
        Set db = Nothing
        
      End Sub


  10. #25
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I'm not going to jump into this...except to point out that the syntax

    Quote Originally Posted by Welshgasman View Post

    Code:
    Private Sub CmdSubmit_Click()
    
    ...........................................
                If Me.TxtTransType = "Transfer" Or "Payment" Then
    ..........................................
    
    End Sub
    is incorrect. It needs to be

    Code:
    If Me.TxtTransType = "Transfer" Or Me.TxtTransType = "Payment" Then
    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #26
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I believe we are now using Select Case logic for txtTransType.

    Quote Originally Posted by Missinglinq View Post
    I'm not going to jump into this...except to point out that the syntax


    is incorrect. It needs to be

    Code:
    If Me.TxtTransType = "Transfer" Or Me.TxtTransType = "Payment" Then
    Linq ;0)>

  12. #27
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @d9pierce1
    RE: Post #18 & #20

    You must know that all caps, especially in the context of a Forum, is the equivalent of shouting?
    If you wanted something to stand out, there are other ways.

    1) In this first condition I want it to insert as long as its a deposit, and the second condition to insert if TRUE"
    2) In this first condition I want it to insert as long as its a deposit, and the second condition to insert if TRUE
    3) In this first condition I want it to insert as long as its a deposit, and the second condition to insert if TRUE
    4) *** In this first condition I want it to insert as long as its a deposit, and the second condition to insert if TRUE ***

    5) *** In this first condition I want it to insert as long as its a deposit, and the second condition to insert if TRUE ***

    6) Separated from other lines by a couple of blank lines


    And I have to say, it kind of irked me also. I didn't think you meant anything by using all caps, but still, it hit me wrong for a second.......



    ---------------------------------------------------------------------------------------------------------------------

    On the coding front:
    In the code in your first post, the following IF will not work.
    Code:
    If Me.TxtTransType = "Transfer" Or "Payment" Then
       ' more code
    End If
    You MUST explicitly do the comparison
    Code:
    If Me.TxtTransType = "Transfer" Or Me.TxtTransType = "Payment" Then
       ' more code
    End If
    This is taken care of by using the "Select Case" option (and I would have suggested Select Case if not already suggested)

    Good luck with your project.

  13. #28
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you and i do oppoligise as it really wasnt ment as yelling!

    In any event, Where are you fininding this code you are quoting?
    If Me.TxtTransType = "Transfer" Or "Payment" Then

  14. #29
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Look at your original post?
    Third IF statement

    Quote Originally Posted by d9pierce1 View Post
    Thank you and i do oppoligise as it really wasnt ment as yelling!

    In any event, Where are you fininding this code you are quoting?
    If Me.TxtTransType = "Transfer" Or "Payment" Then

  15. #30
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    correct, it get inserted no matter what...

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Case Select Question for muti forms
    By d9pierce1 in forum Programming
    Replies: 2
    Last Post: 09-15-2019, 06:19 PM
  2. How to hide Access Options button?
    By ezz in forum Access
    Replies: 3
    Last Post: 11-24-2014, 11:58 AM
  3. Muti Value Export to Excel
    By bboudreau in forum Programming
    Replies: 1
    Last Post: 01-16-2012, 06:43 PM
  4. Access Options Button
    By 95DSM in forum Programming
    Replies: 1
    Last Post: 08-16-2010, 03:05 PM
  5. Toggle Button Options
    By Matthieu in forum Forms
    Replies: 2
    Last Post: 11-23-2009, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums