Results 1 to 4 of 4
  1. #1
    nosmoke is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Location
    Calgary, Canada
    Posts
    2

    Can't Figure Out Why Code Doesn't Work

    I have the following bit of test code which, in my attempts to learn something about Access 2010 VBA, is based mainly from examples found in "Access 2007 VBA Programming for Dummies".

    Dim cnnX As ADODB.Connection
    Set cnnX = CurrentProject.Connection
    Dim myRecordSet As New ADODB.Recordset
    myRecordSet.ActiveConnection = cnnX

    myRecordSet.Open "Select [First Name], [Last Name] From [Admissions] WHERE ([Address] Like 'Box 1954')"

    myRecordSet.MoveFirst
    Debug.Print myRecordSet.Fields("First Name").Value

    The above code works i.e the correct "First Name" is printed in the Immediate window.

    However, again following an example in the Dummies manual, if the middle line of code is changed to:

    myRecordSet.Open "Select [First Name], [Last Name] From [Admissions] WHERE ([Address] Like '*ox 1954')"

    i.e. the "B" in "Box 1954" is changed to a wild card character, the code abends with a message indicating a record(s) was not found.

    The relevant example code portion in the Dummies manual is:

    ..... WHERE ([Email] Like '*@aol.com*')" which appears to be the same syntax as my case.

    Could anyone please tell me why my code doesn't work...

    TIA for any assistance.







  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    What does 'abends' mean?

    The * is a wildcard character. The constructed SQL must not be recognizing the wildcard. Review http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

    What that comes down to is try using % instead of *. It worked for me when I tested your code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nosmoke is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Location
    Calgary, Canada
    Posts
    2
    Many thanks June7! The % worked as advertised. I also see from the article that ? must be replaced by _.

    Strange all that because the Dummies examples are ADOB so I wonder why it supposedly worked for them. Must be differences between VBA 2007 and Access VBA 2010. Actually I was wondering if I would eventually run into such problems (have to get a more appropriate manual I guess).

    BTW, I guess I'm dating myself with the "abends" terminology. It was common back in the 60s and 70s as applied to mainframe computing IIRC and simply stood for
    "abnormal ending" i.e. the failure of a program to run properly, usually indicated by program termination and an error message(s).

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Must be an oversight by the author. I get same behavior with Access 2007.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 12-04-2012, 01:03 AM
  2. My query code doesn't work
    By blacksaibot in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 02:59 PM
  3. Replies: 3
    Last Post: 02-08-2011, 11:39 AM
  4. !!!!Urgent!!!! Search code doesn't work!
    By Laetilae in forum Programming
    Replies: 4
    Last Post: 12-13-2010, 10:34 PM
  5. Query doesn't work when launched by code
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-24-2009, 09:52 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