Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004

    Unanswered: DoCmd.OpenForm - getting type mismatch error

    After two days of searching and trying different approaches, I am seeking the community’s help.

    I am trying to open a form from another form and filter the displayed results based on a numeric and a text field. I keep getting a “Type mismatch” error. If I only use one of the fields (the numeric or text), the function works. If I use both, I get the error message.

    The offending line is:
    DoCmd.OpenForm "frmName", , , "FieldNumeric = " & Me.FieldNumeric And "FieldText = '" & Me.FieldText & "'"

    The FieldNumeric and FieldText are on both the frmName and the form I am calling the DoCmd.OpenForm from.

    What am I doing wrong?

    Thanks for your input.

  2. #2
    Join Date
    Feb 2004
    One Flump in One Place
    Hello there

    Your database may find the below more palatable:

    DoCmd.OpenForm "frmName", , , "FieldNumeric = " & Me.FieldNumeric & " And FieldText = '" & Me.FieldText & "'"

    (changed/ added stuff in red)
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Dec 2002
    Préverenges, Switzerland
    far as i recall, you can't address "frmName" until it is open.

    solution that works (and that i prefer to use cos it lets me pass objects as well as string values):

    in frmName, make a
    public sub initFrmName(param1 as string, param2 as integer)
    FieldNumeric = param2
    FieldString = param1
    then, immediately after docmd.openform "frmName" in the calling form,
    call forms!frmName.initFrmName(fieldText, fieldNumeric)

    solution that might work (but i didn't try):
    immediately after docmd.openform but on new lines (i.e. after the form is open)
    forms!frmName.FieldNumeric = Me.FieldNumeric

    solution that does work (but i don't like cos everything becomes a string):
    pass your values as string openargs.
    the _Load() of frmName can then parse openargs (e.g. separated by commas) and do the setup from there.

    choices choices, izy
    currently using SS 2008R2

  4. #4
    Join Date
    Mar 2004
    Thank you both for your most timely assistance.

    Pootle Flump: I made the changes and and and …. it worked!!! I have even added 2 more fields and the resultant form output works correctly. That & thingy has many uses.

    IzyRider: I will be able to use your idea where I have to pass a couple of objects. Great.

    Pootle Flump and IzyRider, thanks again for sharing your knowledge in this sometimes arcane world of VBA. I have immortalized your thoughts on 20 lb paper and have place the page in my binder O’ documentation and enlightenment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts