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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dLookup Problems 1

Status
Not open for further replies.

access345

Programmer
Nov 23, 2005
78
US
I have created a form to lookup components in a table. The problem I am having is the table I have has multiple designation in the same field. Ex CR2,CR4,CR18
If I am looking up a field that has one designation in it I am fine. But if the field has more than one designation in it my Dlookup returns no information. Some of these fields have more than 50 designations in them. So I am trying to avoid creating new individual records. I will if I have to thou.
 
Change the WHERE clause in your DLOOKUP function to use [FieldName] LIKE "*CR2*
 
Private Sub txtReference_Designator_1_Exit(Cancel As Integer)
Dim X, Y As String
On Error GoTo ERR_txtRef_Desig_1
Forms![frmFailureUpdate]![txtPart_Number_1] = DLookup("LIKE *[COMPANY_PN]*", "Tbl" & [lbCode_Name] & "PartsList", "[REF_DESIG] = Forms![frmFailureUpdate]!txtReference_Designator_1")
Exit Sub
ERR_txtRef_Desig_1:
MsgBox "Information not available. Contact Tom Donahue"
Exit Sub
End Sub

I added your suggestion into my code (above) now nothing works.
 
Can you go back to your original DLookup code? The Like parameter of your DLookup is the third parameter...you changed the first parameter.
 
The field [REF_DESIG] is where CR2, CR4, CR18 codes are stored, correct? And the Forms![frmFailureUpdate]!txtReference_Designator_1 field is where the user enters a code to search for, right? If both are correct, you want to change the LAST parameter of DLookup call "[REF_DESIG] LIKE '*" & Forms![frmFailureUpdate]!txtReference_Designator_1 & "*'
 
Your right I picked the wrong place to put the like statement! You are also right that the ref desig field is where th CR1 .. etc is stored.

This is my current code:

Forms![frmFailureUpdate]![txtPart_Number_1] = DLookup("[COMPANY_PN]", "Tbl" & [lbCode_Name] & "PartsList", "[REF_DESIG]LIKE '*"" = Forms![frmFailureUpdate]!txtReference_Designator_1")
Exit Sub

I had to add the second " mark after the Like '* or I got a compile error.


Original code:
Forms![frmFailureUpdate]![txtPart_Number_1] = DLookup("[COMPANY_PN]", "Tbl" & [lbCode_Name] & "PartsList", "[REF_DESIG] = Forms![frmFailureUpdate]!txtReference_Designator_1")
Exit Sub
 
Forms![frmFailureUpdate]![txtPart_Number_1] = DLookup("[COMPANY_PN]", "Tbl" & [lbCode_Name] & "PartsList", "[REF_DESIG] LIKE '*" & Forms![frmFailureUpdate]!txtReference_Designator_1 & "*'")
 
Just copy and paste the line of code I just posted...it may be tough to distinguish the single and double quotes.
 
Thanks ! Your code works great. I tried 5 or 6 different parts and they all worked great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top