Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form code not working - please help

Status
Not open for further replies.

dab1477

Technical User
Mar 4, 2011
33
US
Thanks in advance.
I created the following code to do the following: After exiting an input form field (HandsetProduct1), I wanted to perform a calculation in another form field (Handset1_EH_CALC) by looking up a specific value (i,e,EARNED HRS standard) using DLOOKUP function, based upon the input of another form box titled cboLocation and multiplying that standard by the qty entered into the HandsetProduct1.

Bottom line...the Dlookup value will be based upon the selection from cboLocation form field.

ISSUE: The following code does NOT display the calculation result within the desired Handset1_EH_CALC field. I get NO error messages and no result. Just blank.

Code:

Private Sub HandsetProduct1_Exit(Cancel As Integer)
If Me.cboLocation.Value = "Teardown" Then
Me.Handset1_EH_CALC.Value = DLookup("[std hrs wght]", "[tbl_handsetstd]", "[location]" = "Teardown_Individual") * Me.HandsetProduct1.Value
ElseIf Me.cboLocation.Value = "Letter Sorting" Then
Me.Handset1_EH_CALC.Value = DLookup("[std hrs wght]", "[tbl_handsetstd]", "[location]" = "Sorting_Individual") * Me.HandsetProduct1.Value
End If
End Sub

Please point me in the right direction. I want to use the cboLocation field input to determine the criteria for the DLOOKUP function, then multiply that lookup value by the qty input into form box HandsetProduct1 field. The result should display in Handset1_EH_CALC field. I will have multiple ELSEIF for 8 possible inputs for cboLocation. Thanks.
 
Try something like:
Code:
Private Sub HandsetProduct1_Exit(Cancel As Integer)
If Me.cboLocation = "Teardown" Then
  Me.Handset1_EH_CALC = DLookup("[std hrs wght]", "[tbl_handsetstd]", "[location] = 'Teardown_Individual'") * _
    Me.HandsetProduct1
 ElseIf Me.cboLocation = "Letter Sorting" Then
  Me.Handset1_EH_CALC = DLookup("[std hrs wght]", "[tbl_handsetstd]", "[location] = 'Sorting_Individual'") * _
    Me.HandsetProduct1
End If
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Nope. Still no value in Me.Handset1_EH_CALC. No error message. Field remains blank. I copied code and directly overwrote. Saved code. Shutdown and restart form. Should I have exited Access? I understood alteration of single vs double quotes at end of DLOOKUP, but why omit .value? Trying to understand, thereby gain enlightenment!
Thanks.
 
Value" is the default property of bound controls so it is optional. Are you actually clicking in the HandsetProduct1 control? I don't really care for storing a value that can be calculated. You might want to use the after update event of the HandsetProduct1 control.

If you are going to write code, you need to understand how to troubleshoot your code faq705-7148.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top