24 minutes ago: Please note that the webserver will soon get its weekly reboot at 4:00 am Eastern Time. You may continue to use the site as normal, but you will be logged off at that time. You should be able to log right back on immediately, however. If you are in the process of placing an order, please make sure to complete it as quickly as possible, or come back after the reboot. Thank you. Sorry for any inconvenience.  Dismiss
 
Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
record source
Erwin 

16 years ago
Hi,

I've been trying to affect the record source of a form but it doesn't seems to go the way i want.

here is my code
-----start code
Private Sub ChoiceList_AfterUpdate()
Dim SQLcode As String
Select Case Me.ChoiceList
       Case 1
           SQLcode = "SELECT * FROM mytbl WHERE age = 1"
       Case 2
           SQLcode = "SELECT * FROM mytbl WHERE age = 2"
       Case else
           SQLcode = "SELECT * FROM mytbl WHERE age > 2"
end Select
end sub

Private Sub GO_Click()
DoCmd.OpenForm "MyForm"
Forms!MyForm.RecordSource = SQLcode
End Sub
-------end code

If i replace, behind RecordSource, the String with one of the SQLcodes it works fine.
but then i need to adjust my entire script and it would be a mess if i need to find adjust something in present.
I thought that this could work too.




Answer from Richard Rost:

The problem is when your form opens, ChoiceList doesn't have a value (even though you might specify a Default value, it doesn't have one).

I would just set the RecordSource to something in the form itself (perhaps show all the records?) and then when the ChoiceList event fires as someone clicks on it, it should readjust the records shown.

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: 8/30/2026 3:54:02 AM. PLT: 0s