Results 1 to 15 of 15
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    if statement with multiple conditions gives Type mismatch error

    The following gives a "Type mismatch" error. txtShrink's format is set to general number. The highlighted line is the ElseIf line. Did I write the if condition wrong?

    If IsNull(Me.txtShrink) Then
    MsgBox ("Enter a shrink rate for the new Material")
    ElseIf (Me.Category = "Metal" Or "Other" And Me.txtShrink <> 0) Then
    MsgBox ("Non plastic parts use zero shrink")


    Me.txtShrink = 0
    Exit Sub
    End If

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The syntax is off; try:

    ElseIf ((Me.Category = "Metal" Or Me.Category = "Other") And Me.txtShrink <> 0) Then

    The type mismatch would imply a numeric/text issue, so double check the data types of both fields.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I think you need something like this:

    ElseIf (Me.Category = "Metal" Or me.category= "Other" And Me.txtShrink <> 0) Then

    oops, I see Paul beat me to the punch

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Try this
    If Not isnumeric(txtshrink) Then
    msgbox("Enter a Shrink Rate for the New Material")
    ElseIF (me.category = "Metal" Or "Other" and me.txtshrink <> 0 Then
    msgbox("Non ....")
    me.txtshrink = 0
    End if
    Exit Sub

  5. #5
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    both Paul and jzw beat me and I missed the Or "OTHER" Portion.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Fastest fingers in the west...or the midwest!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    I'm as far west as you can get (California) but my family moved here from Kansas.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you're in Southern California, there's a pretty good chance that I'm farther west than you are (I'm in Northern Nevada)!

    Do we call you Toto since...wait for it...you're not in Kansas anymore?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    Wow!

    Wow! Thank you for the replies, all of you. I only got to the 1 st one, because it worked like a dream. That darn syntax messes me up every time. Thanks again.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. Note the parentheses I added, which were a guess at your desired logic. When you mix "And" & "Or", you should add parentheses to clarify the logic. Otherwise you might get unexpected results.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    I'm about 120 Miles West of Las Vegas off Interstate 15

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by RayMilhon View Post
    I'm about 120 Miles West of Las Vegas off Interstate 15
    You're so far east of me I can practically call you an Easterner.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Just took a look at a map and guess I need to learn a bostonian accent now.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    LOL! It's one of those trivia questions you can win money with, as everybody assumes that anyplace in CA is west of anyplace in NV, when in fact Reno and Carson City NV are west of Los Angeles.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    I'll have to remember that.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. run-time error '13' type mismatch
    By teebumble in forum Forms
    Replies: 8
    Last Post: 12-03-2012, 01:18 PM
  2. iif statement with multiple conditions
    By ragsgold in forum Queries
    Replies: 7
    Last Post: 08-24-2011, 05:38 PM
  3. Error#13 Type Mismatch
    By Nistin27 in forum Access
    Replies: 8
    Last Post: 08-17-2011, 04:15 PM
  4. type mismatch error?
    By hlcarlin in forum Programming
    Replies: 1
    Last Post: 07-07-2011, 08:30 AM
  5. Replies: 4
    Last Post: 10-26-2009, 05:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums