Home > Blockchain >  Problems Searching in Access
Problems Searching in Access

Time:10-25

Wonder if any of y'all can help me. I keep getting errors on this. Here's my table:

 - tblCutting
    - PartNumber (Primary Key Text Field)
    - CuttingStep1 (Number)
    - CuttingStep2 (Number)
    - CuttingStep3 (Number)

I'm trying to use a combo box (cmbPartNumber1) to pick from PartNumber and then a text box fills in with the corresponding CuttingStep1. Here's are the various formulas I've tried underneath the textbox:

=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [tblCutting]![PartNumber])

=DLookUp("CuttingStep1","tblCutting","[cmbPartNumber1]=" & [tblCutting]![PartNumber])

=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [PartNumber])

=DLookUp("CuttingStep1","tblCutting","[tblCutting]![PartNumber]=" & [cmbPartNumber1])

=DLookUp("CuttingStep1","tblCutting","[PartNumber]=" & [cmbPartNumber1])

None of these have worked and I have no idea why. Any suggestions?

Or am I way off on how this is supposed to work?

Edit: added field types above.

CodePudding user response:

Text values need to be delimited:

=DLookUp("CuttingStep1","tblCutting","PartNumber='" & [cmbPartNumber1] & "'")

Also, since your textboxes are using a calculated formula, they are "Unbound", therefore you need to update their contents yourself.

To handle this you'll need an event sub for the "Change" event of your ComboBox. Add the following code or similar, since I do not know the names of your Textboxes. Add to your Form Module:

Private Sub cmbPartNumber1_Change()
    ' Refresh (recalculate) values.  textBox1,2,3 are names of your Textboxes that contain calculated values based on value of cmbPartNumber1.
    textBox1.Refresh
    textBox2.Refresh
    TextBox3.Refresh
End Sub
  • Related