On Change DLookup

GreenshootProgrammer

Registered User.
Local time
Today, 13:07
Joined
Jan 16, 2013
Messages
74
I have a combo box in a sub form with three values, rate1, rate2, and rate3. I have another three fields in the sub form rate1, rate2, and rate3. The rates are dependent on the item. When I select the rate from the combo box I want a cost field to update on change to the relevant rate. I tried this to no avail:

Code:
txtCost = DLookup(cboRate.Value, "tblItem", "ItemID=" & ItemID)
 
I've tried this too:

Code:
    If Me.cboRate = Rate1 Then Me.txtCost = DLookup("Rate1", "tblItem", "ItemID=" & ItemID)
    If Me.cboRate = Rate2 Then Me.txtCost = DLookup("Rate2", "tblItem", "ItemID=" & ItemID)
    If Me.cboRate = Rate3 Then Me.txtCost = DLookup("Rate3", "tblItem", "ItemID=" & ItemID)
 
I receive the following error message:

Run-time error '2471':
The expression you entered as a query parameter produced this error:
'ITEM001'
 
Your names and explanation are confusing, but your syntax should be something like

Code:
txtCost = DLookup("RateField", "tblItem", "RateName='" & cboRate"'")
replacing

  • RateField with the actual name of the Field, in tblItem, that holds the rate.
    [*]RateName
    with the actual name of the Field, in tblItem, that holds the rate name (i.e. Rate1, Rate2, etc.)
Note that you have to use the Single and Double Quotation Marks as shown.

Linq ;0)>
 
I get a syntax error.

here is an example of the sub form:
_______________________________________
itemid | item | rate | cost | rate1 | rate2 | rate3 |
-----------------------------------------------------------
1 | pen | |v| | £1 | £2 | £3 |
-----------------------------------------------------------

The rates for each item are completely different. When I select the rate from the dropdown box I need the cost to change to the relevant rate.
 
I fixed it by putting the last parameter in square brackets.
G G O O O O A A A L ! ! ! ! ! ! 1 one
 

Users who are viewing this thread

Back
Top Bottom