Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2007, 04:00 AM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Another Runtime 2001 Error

Hi folks,

This routine had been working fine until, one day, it would return a runtime 2001 error. I've added the On Error line so that the program wouldn't get interrupted, but I would like to be able to VBA to manipulate the RecordSource. What am I doing wrong? Thanks for any help you can give.

Private Sub ABttn_Click()

    On Error Resume Next

    Dim SearchStr As String
    SearchStr = "SELECT MedID, MedName, MedSig, MedQuant, MedClass"
    SearchStr = SearchStr + " FROM MedList WHERE (((Left$([MedName], 1)) = 'A'))"
    SearchStr = SearchStr + " ORDER BY MedName"


    Forms![Formulary].RecordSource = SearchStr

End Sub
 
Old April 18th, 2007, 08:50 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Is a different form opening Formulary and then setting it's RecordSource?

If this is the case, I'd try moving the setting of the RecordSource to the Formulary form then make a public sub or function that you pass the criteria to and set it from that form. That should probably clear that up for you. The code itself looks solid. I'd probably also use Forms("Formulary").RecordSource myself.

 
Old April 20th, 2007, 07:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Welcome to P2P!

Try this:

SearchStr = "SELECT MedID, MedName, MedSig, MedQuant, MedClass"
SearchStr = SearchStr & " FROM MedList WHERE [MedName] Like 'A*'"
SearchStr = SearchStr & " ORDER BY MedName"

Note the use of & not +

Note I used the Like comparison. Using Like '*A*' means anything with an "A" anywhere in it. Using Like 'A*' is anything that STARTS with an "A".



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old April 20th, 2007, 05:57 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your replies.

Allen - the routine is already in the "Formulary" form, but still gets the runtime error. I also tried making the variable public without success.

Greg - I tried your codes and they seem to be working great! Hopefully, they'll continue to run without errors. As I mentioned in my original post, my original lines of codes were working fine until it suddenly encountered the error. I still don't know why. Thanks for your help!!

 
Old April 23rd, 2007, 04:32 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

jladder,

Have you changed your version of office at all?

I had similar problems to this, I had an application developed in 2000, when the office upgraded to 2005, of course the program still worked, but the reference to Excel/Access 10 caused errors to pop up with "Function not found" and other weird things.

I re-referenced the code on a 2005 machine and all worked fine after that..

Just thought I would add this as normally, when your code falls over for no reason, theres a reason outside of the code.

Regards,
Rob

 
Old May 25th, 2007, 05:22 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just an update folks. So far, everything is still running smoothly. And Rob, in response to your question, I developed the program in 2000, and am still using that version. Thanks again for your replies.

Jake






Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does it show Link error 2001? Jams Visual C++ 2 July 10th, 2007 05:15 AM
Please Help! getting Runtime error 2001 Waseem Raja Access VBA 2 April 13th, 2007 07:50 AM
Runtime Error 2001 ketAccess Access VBA 2 April 11th, 2007 03:44 AM
Run-time error 2001 kcolli20 Access VBA 1 October 3rd, 2006 07:00 AM
Run-time error 2001 ebburks Access 1 June 8th, 2006 06:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.