Results 1 to 2 of 2
  1. #1
    bxdobs is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    35

    Thumbs up Two possibly common mistakes casual coders should be aware of

    As a result of the never-ending Cyber Policy changes with restrictions to how EMAILS can be sent (emails forwarded by our website's forms are being blocked), resulted in dredging up an old application in ACCESS that pulls down form data and then SENDs NOTIFICATION and CONFIRMATION emails via SMTP services.

    As a casual Access programmer, what I had expected should have been a quick job has turned into more than a couple of weeks due to some very likely COMMON mistakes



    1) SLOPPY/LAZY USE OF ERROR HANDLING ... USE "ON ERROR RESUME NEXT" VERY CAREFULLY (I have repositioned this to the location where it was needed)

    2) in conjunction with 1, DAO "FINDFIRST" does find a record ... just NOT the one you expect if you don't use "dbOpenDynaset"

    Example:
    Using a procedure that is passed in 3 parameters representing FID, PID, and Application
    Code:
    function fnXML( vFID as Variant, vPID as Variant, vApp as Varaint) as Boolean
    xPath = <global data path>vFID-vPID<.xml> provides the procedure with a link to an xml file that it is supposed to import (generating a record)

    Code:
    Application.ImportXML DataSource:=xPath, ImportOptions:=acAppendData
    Each application has a different set of Fields so to be generic I want to just open this newly created record and pull key data out to include Confirmation or Notification emails

    All Tables/Records use vFID (form id), vPID (process id) as their Primary Key

    Outlook has 5 new ABC application requests waiting to be processed ... each request has a unique FID-PID which is passed to fnXML
    fnXML imports the attached XML file no with no issue

    The issue:
    For my initial coding, I was using a DAO FINDFIRST method to find this new XML imported record ... which took me some time to figure out why ALL my Notification and Confirmation emails contained the SAME DATA

    The key here is the FINDFIRST statement was causing an ERROR because it wasn't happy with my missing the dbOpenDynaset ... the RESUME NEXT just ignored the error, as it was told to do, and the NOT xs.NOMATCH was happy because there was a record available to review (albeit the SAME record EVERY TIME)


    Code:
    ON ERROR RESUME NEXT ' SLOPPY/LAZY ERROR HANDLING
    Dim xs as DAO.recordset
    Set xs = currentdb.OpenRecordset(vApp) ' MISSING dbOpenDynaset param in OpenRecordset
    xs.FindFirst "[TFID] = '" & vFID & "' and [TPID] = '" & vPID & "'" 
    If Not xs.NoMatch Then
    This SQL code Always works and is most likely a better approach to finding records going forward.

    Code:
      Dim sql As String
      Dim xs as DAO.recordset
      sql = "select * from " & vApp & " where [TFID] = '" & vFID & "' and [TPID] = '" & vPID & "';"
      Set xs = currentdb.OpenRecordset(sql)
      If xs.RecordCount > 0 Then
       xs.MoveFirst
    NOTE:
    The RESUME NEXT was originally a last-ditch effort to squash an error imported from an OUTLOOK Email Body which included non-ASCII characters
    When attempting to do a FL.WRITELINE with this string containing non-ASCII characters an error occurs ... using an ON ERROR GOTO I have now redirected these strings to a Procedure that strips all non-ASCII characters and then RESUME NEXT

    Is there a way to quickly check if a string has non-ASCII characters without resorting to using an ERROR TRAP?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    >>Is there a way to quickly check if a string has non-ASCII characters without resorting to using an ERROR TRAP?

    You can loop the string with the Mid() functino and the Asc() function to see the ASCII value of each character.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 01-13-2022, 02:14 AM
  2. Possibly a very simple question
    By Ganymede in forum Queries
    Replies: 1
    Last Post: 12-07-2019, 07:29 PM
  3. Possibly Iif statement? Can you help?
    By aellistechsupport in forum Queries
    Replies: 15
    Last Post: 05-17-2015, 09:14 PM
  4. Replies: 4
    Last Post: 10-12-2013, 03:42 PM
  5. Self Aware Yes no box
    By kd4tgc in forum Programming
    Replies: 2
    Last Post: 02-14-2013, 11:32 PM

Tags for this Thread

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