Results 1 to 6 of 6
  1. #1
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38

    Use Combo Box selection in a calculation


    I am new to Access and I need to use the value selected in the Combo Box in a calculation in my query results. I saved the value in a VBA global variable but then I cannot figure out how to use this VBA global variable in my calculation. There just seems like there should be an easier way to do this but I have been unsuccessful in searching for a solution or trying to figure one out on my own.

    Any help would be appreciated.

  2. #2
    ohmydatabase's Avatar
    ohmydatabase is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    79
    You can use the OnChange Event to define the value of your global variable every time the value of the ComboBox changes. After you define the variable you can also write a bit of code within the OnChange Event to do the desired calculation. (store result in a new variable) Using the result of your calculation, you can assemble an SQL String within VBA that you can then use as a RowSource or whatever else you need an SQL Query for.

    There's a pretty good learning curve on this stuff, but once it clicks you'll start making lots of progress. I hope this helps, good luck.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You can use the value from the textbox directly in the query--unless there is some need for the global variable.

    In general, something along this
    eg. SELECT some fields from YourTable
    Where someField = Forms!YourFormname!yourcomboBox

  4. #4
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38
    I want to use the value entered in the combo box in a new field in my query with a calculation

    NewField = Forms!YourFormname!yourcomboBox * 10

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  6. #6
    ohmydatabase's Avatar
    ohmydatabase is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    79
    Quote Originally Posted by sra2786 View Post
    I want to use the value entered in the combo box in a new field in my query with a calculation

    NewField = Forms!YourFormname!yourcomboBox * 10
    Something you could do is put some VBA on the OnChange Event that runs the SQL Query that @orange is talking about. It seems that you need a "kicker" to trigger either: the value of your ComboBox be added to some table, or to assemble an SQL Query in VBA, which you execute and do any calculation you need.

    I do like @oranges method. If you're using to Query Desinger instead of VBA than I can't really speak on this. I essentially do everything in VBA..

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

Similar Threads

  1. Replies: 5
    Last Post: 05-31-2017, 08:58 AM
  2. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  3. Replies: 5
    Last Post: 04-09-2014, 06:57 PM
  4. Replies: 3
    Last Post: 07-03-2013, 10:38 AM
  5. Record selection based on calculation
    By WEJ in forum Programming
    Replies: 5
    Last Post: 05-30-2013, 01: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