Solved

Setting Combobox rowsource value with a string with embeded variables

Posted on 2004-09-02
7
570 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

867 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