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

Open in new window


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

Open in new window


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
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 6 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 6 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004