Open Form to a specific record with composite key

I am attempting to open a form from another form with code. I would like to open the form to the appropriate record. The code I have written returns a "Type MisMatch" error. Both fields are text fields.

Here is the code:

StLinkCriteria = "trim([Project]) = '" & Me![CBOProj] & "'"
StLinkCriteria = (StLinkCriteria & " AND ") & "trim([LotNo]) = " & "'" & Me![LotInput] & "'"
Debug.Print StLinkCriteria

DoCmd.OpenForm acForm, "F_Maintain_Job_Options", , , StLinkCriteria

The debug print returns this in the immediate window:

trim([Project]) = 'RH Proj 1' AND trim([LotNo]) = '44444444'

I tried this with and without the trim function
Rick RudolphAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
first do a Debug > compile and correct any errors raised
do a compact and repair

then use this code

StLinkCriteria = "[Project] = '" & Me.CBOProj & "' AND [LotNo] ='" & Me.LotInput & "'"

DoCmd.OpenForm acForm, "F_Maintain_Job_Options", , , StLinkCriteria


if you are still getting a "Type Mismatch" then  upload a copy of the db


..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rick RudolphAuthor Commented:
I will try this in the morning. I am curious about the compact and repair. is that specific to my issue, or just a good regular practice?
0
Dale FyeCommented:
Are you certain that the bound column on me.cboProj is text and not numeric?  combo boxes frequently have two columns, an ID column which is hidden from view but is the bound column, and a text column

StLinkCriteria = "trim([Project]) = '" & Me![CBOProj] & "'" _
                         & " AND trim([LotNo]) = '" & Me![LotInput] & "'"
debug.print stLinkCriteria

What gets printed in the immediate window?
0
Rey Obrero (Capricorn1)Commented:
it is a good regular practice, specially if you have a weird thing happening like what you are having.
and the debug > compile is to ensure that your codes will compile
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.