set criteria with combo box on form

  • I'm trying to build a SQL query that hits a table in SQL Server. The query is meant to use some user-selected values from a couple combo boxes on a form in the .adp file frontend. Trouble is, I can't get the query to see the values in the combo boxes. I've tried adding "forms." and "forms!" and the form name and "dbo." and the form name in front of the control name. I've also tried adding ".value" and ".text" after the control name but nothing works. I really don't want to have to go to code for this and just want it work via the RowSource of the control. Thanks for any help.

  • The answer is pretty easy: in code, build the sql statement with the values from the control(s), then assign the sql statement to whatever you want (in my case it was to the RowSource of a combo box). After you assign it to whatever, you'll have to requery the database with the sql statement.

  • I don't know where you're running the query from, the form Record Source or from one of the controls. If you want the query to update the form you can use a SQL Server stored procedure as the record source and pass the parameters through the form's Input Parameters property. Here's an example of what's in the Input Parameters on one of my forms:

    @MethodID int = Forms!frmSelectCleanup!comboMethod, @RunSheetID char = Forms!frmSelectCleanup!comboRunsheet

    Here I am passing the integer parameter @MethodID to a stored procedure using the value selected in the combo box comboMethod and passing the character parameter @RunsheetID to the sp from the value selected in the comboRunsheet combobox. When I first started programming I did this a lot, but as I began to have more parameters and parameters of a different type, I wrote a sub procedure to run a SQL Server stored procedure with options to pass up to 4 parameters and a function to do the same but return a value.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply