Share via

DoCmd.OpenForm Expected: =

Anonymous
2012-06-28T17:45:39+00:00

I'm attempting to pull a row of data in a table by opening a separate form using the DoCmd.OpenForm command. I have raw data that is copied into a text box and the code pulls out the time, tech and customer. That all works fine but the OpenForm is failing me! I CAN run the code as follows:

DoCmd.OpenForm(FrmWho)

But I want to add the where condition "[Tech] = '" & TechName & "'". I applied the single quotes because, as I understand it, strings require them in this case. No matter how I attempt to apply the code, it gives me the Compile Error: "Expected: ="

DoCmd.OpenForm(FrmWho, , , "[Tech] = '" & TechName & "'")

DoCmd.OpenForm(FrmWho, WhereCondition:="[Tech] = '" & TechName & "'")

Neither of these versions work, nor about 30 other attempts I made. What am I missing?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-06-28T17:52:51+00:00

Hallo GrayHelo,

GrayHelo schrieb folgendes:
...

But I want to add the where condition "[Tech] = '" & TechName & "'". I applied the single quotes because, as I understand it, strings require them in this case. No matter how I attempt to apply the code, it gives me the Compile Error: "Expected: ="
DoCmd.OpenForm(FrmWho, , , "[Tech] = '" & TechName & "'")

Try:

DoCmd.OpenForm FrmWho, , , "[Tech] = '" & TechName & "'"
HTH
Gunter


Access FAQ: http://www.donkarl.com

      http://www.avenius.com - http://www.AccessRibbon.com
http://www.ribboncreator.com - http://www.ribboncreator2010.com

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-06-28T18:09:02+00:00

    The form name must be a literal string, or a variable or constant whose value is the name of the form:

    DoCmd.OpenForm "FrmWho", WhereCondition:="Tech = ""'" & Me.TechName & """"

    A couple of points to note:

    1.  By explicitly naming the WhereCondition argument you don't need to include all the extra commas.

    2.  The use of a pair of contiguous quotes characters to represent a literal quotes character is preferable to a single quote character with personal names, which might contain apostrophes, e.g. Cináed O'Siridean.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2012-06-28T18:01:40+00:00

    I could swear I tried that but must've messed something else when I did. It works perfectly now though. Thanks guys!

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-06-28T17:54:20+00:00

    Hey Gray -

    1. Have you tried without the parenthesis?

    DoCmd.OpenForm FrmWho, , , "[Tech] = '" & TechName & "'"

    Was this answer helpful?

    0 comments No comments