Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Type mismatch with lack of data.


    Im having some difficulty generating documents from the system where certain information is missing. Im wondering if thre is an easy change I can make to my code, I can wrap everything in if statements but im sondering if there is an easier change i can make to this code to ignore it if its blank

    Code:
    wrdApp.ActiveDocument.Bookmarks("Town").Select
            wrdApp.Selection.Text = rst("Address_3")
    In this case we do not know the "town" so the VBA stopps with type mismatch.

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    I add this in case of nulls:

    wrdApp.Selection.Text = rst("Address_3") & ""

    or I use a function:

    buildAddr([addr1],[addr2],[addr3])


    Code:
    function buildAddr(pvAddr1, pvAddr2, pvAddr3)
    
    
    dim vAddress if Not Isnull(pvAddr1) then vAddress = pvAddr1
    if Not Isnull(pvAddr2) then vAddress = vAddress & " " & pvAddr2
    if Not Isnull(pvAddr3) then vAddress = vAddress & " " & pvAddr3
    buildAddr = vAddress
    end function

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This might also work:


    vAddress = (pvAddr1 + " ") & (pvAddr2 + " ") & pvAddr3
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks both.

    I knew there would be an easeir way that wrapping everything in if statements.

    appreciate your replies.

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

Similar Threads

  1. Data Type MisMatch
    By Eranka in forum Access
    Replies: 2
    Last Post: 10-23-2019, 04:43 AM
  2. Data type mismatch
    By DMT Dave in forum Access
    Replies: 7
    Last Post: 06-14-2019, 10:00 AM
  3. data type mismatch
    By ottoc in forum Queries
    Replies: 1
    Last Post: 12-02-2014, 09:42 AM
  4. Data Type Mismatch in SQL
    By Phred in forum Queries
    Replies: 2
    Last Post: 01-04-2012, 03:40 PM
  5. Data Type Mismatch
    By timmy in forum Programming
    Replies: 9
    Last Post: 04-12-2011, 03:48 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