How Do I Dynamically Filter the ADP Combo Box Rowsource?

Hi, I have a combo box that works great in my MDB using linked tables, and I am trying to migrate it to an ADP.  The rowsource property in the MDB is as follows:

SELECT SubPeriods.SubStart, SubPeriods.ID_Subperiod, SubPeriods.ID_Plan FROM SubPeriods WHERE ((SubPeriods.ID_Plan)=Forms!AllocationPlanForm!ID_Plan);

ID_Plan is a control on the form that contains a value that must be used to filter the result set.

 In the ADP, I can't get it to work with the WHERE clause.   I get the following error message: "Incorrect Syntax Near !".  I know that ADP is different but I wonder what is the fastest approach to restricting a combo box based on field value.  Is the best approach to build a rowsource string and set the properties on the combo box when the form sends the OnCurrent event?
LVL 3
jm-johnmeyer-usAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omgangIT ManagerCommented:
You can set, and reset, the RowSource property of the combo box from a number of different events, i.e. Form, Open or Control, AfterUpdate or Button, Click

You'd use something like

Private Sub MyField-AfterUpdate()

   Dim strSQL As String

   strSQL = "SELECT SubPeriods.SubStart, SubPeriods.ID_Subperiod, SubPeriods.ID_Plan " _
         & "FROM SubPeriods " _
         & "WHERE ((SubPeriods.ID_Plan)=Forms!AllocationPlanForm!ID_Plan);"

      Me.cboComboBox.RowSource = strSQL
      Me.cboComboBox.Requery

End Sub

OM Gang
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
omgangIT ManagerCommented:
If the current form is AllocationPlanForm then I'd change the WHERE clause to
WHERE ((SubPeriods.ID_Plan)=Me.ID_Plan);"

just typing that may have exposed your error.  I think it needs to be

WHERE ((SubPeriods.ID_Plan)='" & Me.ID_Plan &"');"

note the inclusion of single quotation marks

OM Gang
0
jm-johnmeyer-usAuthor Commented:
Yes!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.