Geting a type mismatch error on code to open form

Using this code I'm getting a type mismatch error.

DoCmd.OpenForm "frmSurveys", acNormal, , "[1RatePerformance]=" & Me.txtCount21 And "[BuyersAgent]=" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID, acFormReadOnly, acWindowNormal

Note that both 1RatePerformance and BuyersAgent are number fields.

????
SteveL13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Jeffrey CoachmanMIS LiasonCommented:
Try these perhaps?

Presuming that txtCount21  is Numeric:
 "[1RatePerformance]=" & Me.txtCount21 & " And " &  "[BuyersAgent]=" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID

Presuming that txtCount21  is text:
 "[1RatePerformance]=" & "'" & Me.txtCount21 & "'" & " And " &  "[BuyersAgent]=" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID

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
SteveL13Author Commented:
It is numeric but it opens a blank form.
Rey Obrero (Capricorn1)Commented:
try

DoCmd.OpenForm "frmSurveys", acNormal, , "[1RatePerformance]=" & Me.txtCount21 & " And [BuyersAgent]=" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID, acFormReadOnly, acWindowNormal


if [BuyersAgent] is TEXT

DoCmd.OpenForm "frmSurveys", acNormal, , "[1RatePerformance]=" & Me.txtCount21 & " And [BuyersAgent]='" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID & "'", acFormReadOnly, acWindowNormal
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dale FyeOwner, Developing Solutions LLCCommented:
As always, I recommend constructing your criteria string outside the openform method, so you can actually see what it looks like, before you open the form.  I would think that the syntax that Jeff provided above would be correct, so try:

Dim strCriteria as string
strCriteria =  "[1RatePerformance]=" & Me.txtCount21 & " And " _
         &  "[BuyersAgent]=" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID
Debug.print strCriteria
DoCmd.OpenForm "frmSurveys", , , strCriteria, acFormReadOnly, acWindowNormal

Open in new window

This should help you determine why it is not opening the form to a record you expect to be there.
Gustav BrockCIOCommented:
Listen to Dale. You have asked this type of questions so many times, and it will save you a lot of time in the future.

/gustav
mbizupCommented:
If the code is not producing any errors, but you are not getting any results it is probably because there are no records in frmSurveys' recorsource meeting the criteria you are specifying.

If you believe that there SHOULD be records matching that criteria... then you may need to save the current record before opening the second form.

This uses Jeff's syntax, with Dale's modifications:

Dim strCriteria as string

DoCmd.RunCommand acCmdSaveRecord  '*** try saving the current record first

strCriteria =  "[1RatePerformance]=" & Me.txtCount21 & " And " _
         &  "[BuyersAgent]=" & Forms!frmSearchForIndividualAgentSurvey.txtAgentID
Debug.print strCriteria
DoCmd.OpenForm "frmSurveys", , , strCriteria, acFormReadOnly, acWindowNormal

Open in new window

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.