Page 3 of 3 FirstFirst 123
Results 31 to 39 of 39
  1. #31
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Thanks,
    I thought we had all ready determined that was not the way to go so i didnt even look at that. I got off on this Case thing which havent been able to make work either.
    Thanks, Sorry about that...

  2. #32
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    What's not working with the Select Case method that you showed in post #24? Are you getting an error, or it doesn't do the inserts properly?

  3. #33
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    you are missing some " and = signs in post 24.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #34
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Davegri
    When i run the code in like post 24, it does absolutely nothing. NO errors, no messages, and does not insert into the table. I fixed the = signs and such in the code but still does notning
    thanks

  5. #35
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    thanks, i seen that and fixed it but it, it doesnt even give me an error when compling

  6. #36
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by d9pierce1 View Post
    Hi Davegri
    When i run the code in like post 24, it does absolutely nothing. NO errors, no messages, and does not insert into the table. I fixed the = signs and such in the code but still does notning
    thanks
    That would indicate that txtTransferNumber is not equal to "Deposit" or "Payment" , "Transfer".
    In fact, its name indicates that it's a number, not a text field. What is TxtRandom?
    To find out, put a
    Debug.print "TransNumber=" & Me.txtTransNumber
    just before the Select Case line.


    If that results in nothing in the immediate window, then the sub CmdSubmit_Click event is not being fired at all.

  7. #37
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by d9pierce1 View Post
    Hi Davegri
    When i run the code in like post 24, it does absolutely nothing. NO errors, no messages, and does not insert into the table. I fixed the = signs and such in the code but still does notning
    thanks
    Walk through the code with F8 after setting a breakpoint.

  8. #38
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you,
    I went back to the Do.Cmd RunSql along with the select case and it worked! Not sure why i cant get the "db.Execute strSql, dbFailOnError" to work but have had issues with that in the past.
    So, here is the code i used and it does exactly what i wanted! Wow
    Thank you all for all suggestions, assistance, and time!
    Code:
    Private Sub CmdSubmit_Click()
    
    
    'Dim strSql As String
    'Dim db As DAO.Database
    'Set db = CurrentDb
       
        Me.TxtTransNumber = [TxtRandom]
    
    
        Select Case Me.TxtTransType
    
    
        Case "Deposit"
        
            If Me.ChkDepositRemburseExp = False Then
                 DoCmd.SetWarnings False
                 DoCmd.RunSQL "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
                 DoCmd.RunSQL "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
                DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                         "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  '" & TxtTransDescription & "' , '" & TxtMethod & "' , " & TxtTransAmount & ")"
                DoCmd.SetWarnings True
            End If
    
    
        Case "Transfer", "Payment"
                DoCmd.SetWarnings False
                DoCmd.RunSQL "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
                DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                           "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboFromAccount.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                DoCmd.SetWarnings True
    
    
        Case "Purchase"
    
    
            If Me.ChkIsRemburseExp = False Then
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL "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
                    DoCmd.RunSQL "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
                    DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                            "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  '" & TxtTransDescription & "' , '" & TxtMethod & "' , " & TxtTransAmount & ")"
                    DoCmd.SetWarnings True
            End If
    
    
        Case "Record Bill"
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                            "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                    DoCmd.SetWarnings True
    
    
    
    
        Case Else
     
        End Select
        'db.Execute strSql, dbFailOnError
        'Set db = Nothing
        
      End Sub

  9. #39
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You keep chopping and changing what variable you are using in you select Case.

    If you are testing transnumber for "Deposit" and that does not even look right?, then there is no strSQL, so nothing to execute?
    Now you have changed it back to txtTranstype and the Case statement will work?

    Good luck anyway.

    Quote Originally Posted by d9pierce1 View Post
    Thank you,
    I went back to the Do.Cmd RunSql along with the select case and it worked! Not sure why i cant get the "db.Execute strSql, dbFailOnError" to work but have had issues with that in the past.
    So, here is the code i used and it does exactly what i wanted! Wow
    Thank you all for all suggestions, assistance, and time!
    Code:
    Private Sub CmdSubmit_Click()
    
    
    'Dim strSql As String
    'Dim db As DAO.Database
    'Set db = CurrentDb
       
        Me.TxtTransNumber = [TxtRandom]
    
    
        Select Case Me.TxtTransType
    
    
        Case "Deposit"
        
            If Me.ChkDepositRemburseExp = False Then
                 DoCmd.SetWarnings False
                 DoCmd.RunSQL "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
                 DoCmd.RunSQL "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
                DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                         "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  '" & TxtTransDescription & "' , '" & TxtMethod & "' , " & TxtTransAmount & ")"
                DoCmd.SetWarnings True
            End If
    
    
        Case "Transfer", "Payment"
                DoCmd.SetWarnings False
                DoCmd.RunSQL "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
                DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                           "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboFromAccount.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                DoCmd.SetWarnings True
    
    
        Case "Purchase"
    
    
            If Me.ChkIsRemburseExp = False Then
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL "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
                    DoCmd.RunSQL "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
                    DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
                            "VALUES (" & TxtTransID & ", " & CboRE & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "',  '" & TxtTransDescription & "' , '" & TxtMethod & "' , " & TxtTransAmount & ")"
                    DoCmd.SetWarnings True
            End If
    
    
        Case "Record Bill"
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
                            "VALUES (" & TxtTransID & ", " & CboToAccount & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & " From " & CboCompany.Column(1) & "', '" & TxtMethod & "' , " & TxtTransAmount & ")"
                    DoCmd.SetWarnings True
    
    
    
    
        Case Else
     
        End Select
        'db.Execute strSql, dbFailOnError
        'Set db = Nothing
        
      End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 3 of 3 FirstFirst 123
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