Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Need Guidance with my Listbox
Sandra Truax 
         
2 years ago
Me and ChatGPT are about to fight!  Neither one of us can figure this out.

I have a listbox I use instead of so many buttons. Everythign works except getting it to run VBA code.  If the code is in a module, it works.  The problem is that when the code is in a form, and even if it is a Public Sub, I get an error saying it can't be found.  

If anyone can give me guidance while I have hair left, I will be very grateful!  I have notes in the code.

  ElseIf MyList.Column(1) = "Datasheet" Then
        DoCmd.OpenForm MyList.Column(2), acFormDS
    ElseIf MyList.Column(1) = "VBA" Then
    
        'This code works with code in Modules
        'Application.Run MyList.Column(2)
        
        'This code is for a Public Sub in another form but does NOT work
        Application.Run 'MyList.Column(3) & "." & MyList.Column(2)
        ' Column(3) is the name of the form with the Public Sub
        ' I've tried entering the form's name as "Form_DatabaseF" and as just "DatabaseF"
        ' Msgbox results show Form_DatabaseF.SelectAllDatabases OR DatabaseF.SelectAllDatabases
        ' Every time it says Object not found.
        
        DoCmd.OpenForm MyList.Column(5), acNormal
        Exit Sub
    End If
David Burns  @Reply  
    
2 years ago
Just checking... Application.Run 'MyList.Column(3) & "." & MyList.Column(2)
Is the single quote before MyList.Column(3) supposed to be there?
Kevin Yip  @Reply  
     
2 years ago
The names that begin with "Form_" are form class modules, and the procedures inside them are relevant only to the forms.  Application.Run can only run global procedures inside stand-alone modules (see picture below), but not the ones inside form modules.  That is why you get "object not found" error.  The only way to run a form module's procedures is to call them directly.  Go to the immediate window and type:

     Form_MyFormName.MyProcName

and it will run (barring run-time errors).

If ChatGPT gave you the erroneous code, then it just doesn't understand some of the intricacies of the VBA object models.  This is not really an issue with listboxes, but an issue with how to refer to form procedures properly.
Kevin Yip  @Reply  
     
2 years ago

Sandra Truax OP  @Reply  
         
2 years ago
Thanks, Kevin for explaining this to me. Now I understand what is going on.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 6:15:58 AM. PLT: 0s