Automatically fills in a Value dependant on a Combo Box in a Form - Access 2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kitty001
    New Member
    • Oct 2008
    • 3

    Automatically fills in a Value dependant on a Combo Box in a Form - Access 2007

    Hi Guys
    I am new to MS Access and using MS Access2007.
    I have been fooling around with Access trying to solve this problem for weeks but i just cant seem to chack it and I need some help.

    I have a database based on the machines used for the maintenance of a golf course here in South Africa.
    I have tables containing the "Groups of Machines", "Machines" and the "Types of Fuel" they use with Prices per Lt.

    I have created a form thats been working fine but theres still a few things i need it to do for me and would appriciate all the help i can get.

    In the Form I have 2 combo boxes
    -GroupID
    -Machines

    In "GroupID" you choos the Group Of Machine that the "Machine" falls under and in Machines you choos the specific machine. Which works perfectly.
    ie. GroupID: Fairways
    Machines: S14 (Machine Code)

    Then i have another combo box where you can choos what type of fuel was used.
    ie. Petrol, Diesel,Oil, Hydrauic Oil,ect.

    Now what i want it to do is when i choos a value from the "Fuel" combobox i would like the price per Lt to automatically apear in the Price field.
    Now to the feeling i have it probably have something to do with the AfterUpdate Event in the Property sheet

    I would have attached a image of the form but i have no idea as to how i do that

    Thanks A million
    Kitty//*
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Try something like as shown below (replace the object names I used with their actual names in your application. Also, I am assuming that the price is in the 3rd column of your combobox. Keep in mind that column indexes start at 0 in ms access, so the third column will have an index of 2. Finally, I have assumed that txtPricePerLt is a textbox control on your form to display the price.

    Code:
    Private Sub cboFuelType_AfterUpdate()
    
    txtPricePerLt = Me!cboFuelType.Column(2)
    ' Me.Requery        this line commented out......reactivate if needed.
    
    End Sub
    Last edited by puppydogbuddy; Oct 8 '08, 09:31 PM. Reason: commented requery line out

    Comment

    • Kitty001
      New Member
      • Oct 2008
      • 3

      #3
      Hi
      Thanks for the quick reply but im i bat lost with the Index Parts. x_x

      and also i dont understand the "Column" in the following statement.
      txtPrice_per_Lt = Me!cboType_of_F uel.Column(2)

      Im trying my best to study VBA my own time, So i can understand a bit more.

      ps..
      My Price per Lt Control in the form is a Currency box as there has to be a Price with the south african Rand Value in.

      Comment

      • Kitty001
        New Member
        • Oct 2008
        • 3

        #4
        Hi
        Thanks for the quick reply but im i bat lost with the Index Parts. x_x

        and also i dont understand the "Column" in the following statement.
        txtPrice_per_Lt = Me!cboType_of_F uel.Column(2)

        Im trying my best to study VBA my own time, So i can understand a bit more.

        ps..
        My Price per Lt Control in the form is a Currency box as there has to be a Price with the south african Rand Value in.

        Comment

        • puppydogbuddy
          Recognized Expert Top Contributor
          • May 2007
          • 1923

          #5
          Originally posted by Kitty001
          Hi
          Thanks for the quick reply but im i bat lost with the Index Parts. x_x

          and also i dont understand the "Column" in the following statement.
          txtPrice_per_Lt = Me!cboType_of_F uel.Column(2)

          Im trying my best to study VBA my own time, So i can understand a bit more.

          ps..
          My Price per Lt Control in the form is a Currency box as there has to be a Price with the south african Rand Value in.
          The columns and column indexes refer to the columns of data in your combobox. In Access, you can refer to the individual columns by their column index.

          I recommend you take the free tutorial(s) at the following link to answer your general questions. This site is one of the best free tutorial sites on the web. If you still need help with specific questions after doing the tutorial(s), then post back here.

          Comment

          Working...