We help IT Professionals succeed at work.

Populating datasheet subform from VBA

Lynne Malchiodi
on
125 Views
Last Modified: 2017-03-15
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!
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I checked the table definition, it's a short text field.
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
OK.  Did you also do the second check I suggested?

Author

Commented:
Oops, responded before I'd tried your second check. It was the master/child links; I had them specified. When I removed that, the search works as it should. Thank you very much!

Author

Commented:
I've marked the solution, thanks again for the help!
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
You're welcome.  Glad to help.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.