Results 1 to 10 of 10
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Setting a combo box to a default?

    Hi all,


    On my form I have a Combo for accounts. Is ther a way to get this to only be one account as a default or set a value to it on the RunSql statement (Below)?

    Code:
        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
    The CboRE (in Red) above would be ideal to be able to use for this if possible? This is a combo with all accounts and is hidden on my form. I want to be able to just set that as Remburseable Expenses
    so that i dont need to select it. It would always be the same value.... CboRE = Rembursable Expenses

    I coule also use the "ChkDepositRemburseExp" check box so that when ticked, it sets that CboRE to Rembursable Expenses

    Not sure how to actually do this? I have tried bound and unbound in different combos, have tried a default value however nothing has produced a result. Maybe some type of Qry? I just dont know

    Thanks
    Dave

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Make the combo unbound and in the Load event of the form (or before you run the code you show) add Me.cboRE="Rembursable Expenses"

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,926
    If the combo is unbound, you can set the default property?
    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

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you so much...\

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    OK,
    Gave that a shot however, unless i actually select that from drop down "Rembursable Expenses" it give me an error when running the code. It does put "Rembursable Expenses" in the unbound Cbo yet it doesnt actually select that account from the drop down if this makes any sense at all?
    Basically i get a compile error Verible Not Defined... if i put Me.cboRE="Rembursable Expenses" in the onload event but if i select it from the cbo then code runs just fine

    So what i am trying to say, it puts the words in that combo
    "Rembursable Expenses" but doesnt actually select the account "Rembursable Expenses"

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Actually the only time i need the "Rembursable Expenses" even in that combo is when i click the "ChkDepositRemburseExp" on form so would it be better to maybe use a onclick method with a DLookup and set to "Rembursable Expenses"

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,926
    I would not have thought that cboRE was actually "Rembursable Expenses", but an ID equivalent to "Rembursable Expenses" ?

    What is the source for cboRE ?
    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

  8. #8
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Welshgasman,
    You are correct, It is an ID for AccountTbl, (AccountID and AccountName) and Rembursable Expenses is one of the accounts.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,926
    Quote Originally Posted by d9pierce1 View Post
    Hi Welshgasman,
    You are correct, It is an ID for AccountTbl, (AccountID and AccountName) and Rembursable Expenses is one of the accounts.
    So the default is whatever the ID is for Rembursable Expenses ?
    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

  10. #10
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    yes sir, thats the idea. ID # is actually 21

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Default Database Setting
    By Perceptus in forum Access
    Replies: 3
    Last Post: 06-30-2015, 02:11 PM
  2. Setting default
    By Thompyt in forum Programming
    Replies: 10
    Last Post: 11-10-2014, 11:49 AM
  3. Replies: 3
    Last Post: 04-27-2014, 05:54 PM
  4. Setting Variable Default for Combo Box
    By gazaway in forum Forms
    Replies: 5
    Last Post: 04-08-2013, 10:32 AM
  5. Replies: 4
    Last Post: 11-04-2012, 10:46 AM

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