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?
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?
you would need to move the "db.Execute strSql, dbFailOnError" from the bottom of the procedure and insert it after each strSql statement.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
If this helped, please click the star * at the bottom left and add to my reputation- Thanks
My wife can shout at me because I let her think she's the boss."IN THIS FIRST CONDITION I WANT IT TO INSERT AS LONG AS ITS A DEPOSIT, AND THE SECOND CONDITION TO INSERT IF TRUE"
Not going to take it from you though. Ciao.
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.
LOL, wasnt shouting my friend, just wanted to make it so it stood out!
Yep, thats what i hope to do
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
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.
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
I'm not going to jump into this...except to point out that the syntax
is incorrect. It needs to be
Linq ;0)>Code:If Me.TxtTransType = "Transfer" Or Me.TxtTransType = "Payment" Then
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
@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.
You MUST explicitly do the comparisonCode:If Me.TxtTransType = "Transfer" Or "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)Code:If Me.TxtTransType = "Transfer" Or Me.TxtTransType = "Payment" Then ' more code End If
Good luck with your project.
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
correct, it get inserted no matter what...