Solved

Setting Combobox rowsource value with a string with embeded variables

Posted on 2004-09-02
7
594 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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