Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Setting Combobox rowsource value with a string with embeded variables

Posted on 2004-09-02
7
Medium Priority
?
618 Views
Last Modified: 2012-05-05
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
Comment
Question by:ajaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11967447
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11967463
what are you trying to put as the row source of the combo box?

a query

Select Distinct Names From TableNAmes;
0
 

Author Comment

by:ajaac
ID: 11968476
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 500 total points
ID: 11969241
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
 

Author Comment

by:ajaac
ID: 12019427
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12019508
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
 

Author Comment

by:ajaac
ID: 12020480
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question