Solved

Setting Combobox rowsource value with a string with embeded variables

Posted on 2004-09-02
7
565 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 125 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now