[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

Setting Combobox rowsource value with a string with embeded variables

I'm trying to set the row source of a combobox with a string which has an embeded variable.

I will be accessing the string data from a table and want to load the combobox with the approiate data.  

the string I want to use is like the following

str="Exec spDoSomething ' " & myParameter & " ' "

what I need this to do is set the row source to this:

rowsource= Exec spDoSomething '33'

I have tried eval() and can not seem to find a way to make this work.

I will be accessing the string data from a table and want to load the combobox with the approiate data.

0
ajaac
Asked:
ajaac
  • 3
  • 2
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
the

RowSource Specifies the name of the table, query, or SQL statement if RowSourceType is set to Table/Query. Specifies the entries in the list, separated by semicolons, if RowSourceType is set to Value List. Specifies the name of the table or query if RowSourceType is set to Field List. Is blank if RowSourceType is set to a function name.
0
 
Rey Obrero (Capricorn1)Commented:
what are you trying to put as the row source of the combo box?

a query

Select Distinct Names From TableNAmes;
0
 
ajaacAuthor Commented:
In this situation I am setting the row source to  execute a stored procedure on an sql sever the value in the single quotes is a prameter for the procedure.

This is how I normally set the row source, the difference in this case is that I want to store the procedures I will be using in a table, the choice will be controlled elseware in my code.

The goal is to set the rowsource to execute the proper procedure with the proper parameters!

I have stored in my control table, a string equal to what I want to put in the row source.

My question is how to convert this string to a string with the embeded parameter evaluated.

Example.

If I include in an on-open event on the form the following statement it will set the row source correctly.

me.combo1.rowsource = "Exec spMyProc ' " & myParameter & " ' "
me.combo1.requery

Assuming the variable myParameter = 33, this will set my row source to
Exec spMyProc '33'
Which is what I want.  

Now I want to store the value "Exec spMyProc ' " & myParameter & " ' "  in a table and load the rowsource on demand.

In debug if I try this it prints correctly.
debug.print "Exec spMyProc ' " & Eval(myParameter) & " ' "

So how can I get this loaded to the rowsource property of my combo box?


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shanesuebsahakarnCommented:
Hmm, could you not lookup the the rowsource string and then do a Replace, as in something like:

strRowsource="Exec spMyProc '%MYPARAMETER%'"
strParameter="33"
strRowsource=Replace(strRowsource,"%MYPARAMETER%",strParameter
Me!Combo1.RowSource=strRowsource
Me!Combo1.Requery
0
 
ajaacAuthor Commented:
If I use this method I will need to parse my string for the  parameter (MYPARAMETER in your example)  then I need to determine the value of the parameter.  (Assigned 33 in your example)

Do you have any better Ideas than something like this?
Parametervalue = Eval(""" & parsedparameterstring & """)

Thanks
Allen
0
 
shanesuebsahakarnCommented:
You need some way of inserting the hardcoded parameter value into the string retrieved from the table, and this is one of the best ways I can think of. How do you obtain the value of myParameter in the first place (taking your original example)? Is it a particular value?
0
 
ajaacAuthor Commented:
The parameters are just  variables in most cases, but the only way to determine their value( that I know of) is to use the Eval statement.

I was really hoping someone had done this before.  My goal is use comboboxs to allow a user to determine parameter values for some reports, I have a table that will contain the rowsource string by report name, when a user selects a report, the comboboxs will be loaded with the proper values, these are stored procedure on an SQL server and some require the parameters we have been discussing.  

I'm awarding you the points because you at least came to the same method I was tring to get around.

Thanks for your help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now