Pass a value to calculated field from different table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarcinM
    New Member
    • Nov 2014
    • 15

    Pass a value to calculated field from different table

    Hello,
    There are 3 tables with fields as shown below. All the tables are on the same form.
    Side One: tblOrders
    Side Many: tblOrderDetails , tblExchangeRate s

    I would like to make a calculated field “Value” in tblOrderDetails .
    How can I pass to this calculated field the value of exchange rate field from tblExchangeRate s?

    Thank you for any hints.

    tblOrders (one side)
    orderID (PK)
    (other fields)

    tblOrderDetails (many side)
    orderElementID (PK)
    orderID (FK)
    elementName
    Quantity
    Price
    CurrencyName
    Value (=Quantity*Pric e*exchangeRate)
    (other fields)

    tblExchangeRate s (many side)
    exchangeRateID (PK)
    orderID (FK)
    currencyName
    exchangeRateVal ue

    PK – primary key
    FK – foreign key


    Marcin.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1290

    #2
    MarcinM,
    Welcome to Bytes.com. Always good to see new posters.

    Why is OrderID in the tblExchangeRate s? One could assume that the exchange rate does not vary by order but by currency being used by the customer. Once you know the customer, you know the currency, and you can use Dlookup function to pull the exchange rate from the the exchange rate table (orderID not being necessary for the lookup).

    Does this help?

    jim

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3653

      #3
      MarcinM,

      I also am unclear as to how all three tables are on one form? If anything, these should be subforms of the main form (depending on which is your master table--Orders?).

      Comment

      • MarcinM
        New Member
        • Nov 2014
        • 15

        #4
        Thank you for your answers.
        A few words of explanation

        << Why is OrderID in the tblExchangeRate s?
        << One could assume that the exchange rate does not vary
        << by order but by currency being used by the customer.
        There may be MANY currency names in ONE order, that is why OrderID is in tblExchangeRate (side many of the relation).

        << I also am unclear as to how all three tables are on one << <<< form?
        Master table - tblOrders (main form)
        Both tblExchangeRate s and tblOrderDetails are on the subform.

        The idea is that when a user chooses a curreny name (in tblOrderDetails on the subform)an appropriate exchage rate will be drawn from tblExchangeRate (based on OrderID, currencyName).

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3653

          #5
          When someone chooses a currency type, simply filter the exchange rates subform based on that value.

          Comment

          • MarcinM
            New Member
            • Nov 2014
            • 15

            #6
            Thank you for your posts.

            The following solution seems to be working
            I assigned "currencyNa me" to a query and refer to necessary columns using VBA (columnt(x))

            Code:
            Private Sub PoleKombi_AfterUpdate() 
             me.exchangeRateID = Me.comboBox.Column(1) 
             me.currencyName=  Me.comboBox.Column(2) 
             me.exchangeRate = me.comboBox.Column(3) 
             me.value = Quantity*Price *exchangeRate)
            end sub
            Last edited by Rabbit; Nov 30 '14, 05:49 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

            Comment

            Working...