+ Reply to Thread
Results 1 to 4 of 4

VBA to make numeric value short text

  1. #1
    Registered User
    Join Date
    07-27-2021
    Location
    NL
    MS-Off Ver
    2013
    Posts
    8

    VBA to make numeric value short text

    Good morning everyone,

    I'm getting Data type mismatch in criteria expression on a VBA that I'm using, I'm not the author, it was working fine until upgrade from office 2013 to 365.

    The code:
    Please Login or Register  to view this content.

    Using debug.pring I know that second sql string results in this:

    Please Login or Register  to view this content.

    If my understanding is correct the error comes from 1904 value that is numeric in sql while Mtbl_02_Recharge_FixedAmounts.[YYMM Last month of Fixed Amount] is stored as short text.
    I tried to modify like this:
    Please Login or Register  to view this content.
    But it makes no difference. I'm not so good with VBA in access, I don't think I can solve it on my own, please help!

  2. #2
    Registered User
    Join Date
    03-19-2022
    Location
    TBD
    MS-Off Ver
    O365
    Posts
    46

    Re: VBA to make numeric value short text

    Hi Marcinrd,

    Since RRMonth is already declared as string, but if the source data is numeric then the problem could be at the expression : RRMonth = rst.Fields("Process Month (YYMM)").
    My guess is the value stored in Process Month (YYMM) field may be a numeric value. You may try to use function CStr() to convert numeric data type to string data type.

    Please try to change RRMonth = rst.Fields("Process Month (YYMM)") to RRMonth = CStr(rst.Fields("Process Month (YYMM)")).
    Another way is you may try to run in debug mode, so it will show the line that caused an error.

  3. #3
    Registered User
    Join Date
    07-27-2021
    Location
    NL
    MS-Off Ver
    2013
    Posts
    8

    Re: VBA to make numeric value short text

    Thank you chocolate_kitten! It put me on right track
    CStr(rst.Fields("Process Month (YYMM)")) alone didn't work but combined with my first attempt of adding ' in sql those two methods together finally gave the right result!

  4. #4
    Registered User
    Join Date
    03-19-2022
    Location
    TBD
    MS-Off Ver
    O365
    Posts
    46

    Re: VBA to make numeric value short text

    congratulations!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Want to make short a formula
    By Mofasol in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2020, 10:57 PM
  2. Replies: 2
    Last Post: 01-16-2018, 06:52 PM
  3. How to make the short border?
    By ajing in forum Excel General
    Replies: 3
    Last Post: 01-27-2016, 02:56 PM
  4. Userform find/search text, can i make it's short code ?
    By johnreid7477 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-03-2014, 04:28 PM
  5. [SOLVED] How to Short sheet name by two kinds of sheets names( alpabet then numeric )
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2013, 12:16 AM
  6. [SOLVED] VBA code to make multiple text boxes numeric entry only
    By JAL_0110 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-20-2013, 01:57 AM
  7. [SOLVED] Make Excel allow numeric fields as text
    By Michael A. Covington in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2006, 11:10 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1