Avatar of SteveL13
SteveL13
Flag for United States of America asked on

Left$ question

In have a report that has the following onprint event in the detail section of the report.  

    If Me.chkbxDirectShip = True Then
        Me.txtEaPrice = DLookup("[ATPriceEa]", "tblParts", "[PartN] = '" & Me.txtPartN & "'")
    End If

But the "me.txtPartN" portion of the code needs to be the left characters of the txtPartN up to the first space in the txtPartN.  I know this may be confusing but can someone help?

In other words, if the actual PartN is "123456 - Test" then I want it to think the PartN is "123456" (ignoring the rest of the string).

I've tried:
Me.txtEaPrice = DLookup("[ATPriceEa]", "tblParts", "[PartN] = '" & Left$, Me.txtPartN & "'")
but that isn't even close I'm sure.

--Steve
Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
mbizup

Instead of left try

Split(txtpartn, " ")(0)
SteveL13

ASKER
This is not working:

Me.txtEaPrice = DLookup("[ATPriceEa]", "tblParts", "[PartN] = '" & Split(txtPartN, " ")(0))

I get a syntax error message. 3075.
ASKER CERTIFIED SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mbizup

Very close... You just need to close the embedded quotes:


Me.txtEaPrice = DLookup("[ATPriceEa]", "tblParts", "[PartN] = '" & Split(txtPartN, " ")(0) & "'")

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Gustav Brock

Oopss:

Me.txtEaPrice = DLookup("[ATPriceEa]", "tblParts", "[PartN] = '" & Val(Me.txtPartN) & "'")

/gustav