troubleshooting Question

Populating datasheet subform from VBA

Avatar of Lynne Malchiodi
Lynne Malchiodi asked on
Microsoft Access
6 Comments1 Solution135 ViewsLast Modified:
I'm not very familiar with using subforms, and can't figure this one out. I've got a datasheet subform on a search form. I have the user enter a value for donor_id and click a search button. On the click event for the search button, I do this:

strSearch = Me.txtDonorID.Value
strSQL = "SELECT Donor.* FROM Donor Where DONOR_ID = '" & strSearch & "'"
Me.SubDonorList.Form.RecordSource = strSQL
Me.SubDonorList.Form.Requery

The very first DONOR_ID in the table is 1, and there are two records with that ID.  When I search for a donor ID of 1, it correctly populates the subform with the two records. When I search for any other donor ID  in the table, the subform is empty.  I've stepped through the code and confirmed that I've got the right variables at each line, and I've tried pasting the SQL command (strSQL) into a query, with donor IDs of varying lengths. It works fine. So I'm pretty confident that the code, quotes, etc, are correct.

I've also tried this, which gave the same results. Datasheet is populated if the donor ID =1 , not if it's any other string.

strSearch = Me.txtDonorID.Value
Me.SubDonorList.Form.Filter = "[DONOR_ID] = '" & strSearch & "'"
Me.SubDonorList.Form.FilterOn = True
Me.SubDonorList.Form.Requery

Since I'm kind of new to subforms, I'm assuming that that's where my problem is. I've gone through the properties over and over again, and I'm not seeing it.  Does anyone recognize this issue? Thanks so much!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros