Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stumped on easy variable pass from combo box

Status
Not open for further replies.

pvsmith5

Programmer
Mar 22, 2004
52
US
I'm having a tough time with something that should be a snap. I have a combo box on a form and I just want to move the values from the combo box to the code so that each time the code runs, it selects the combo box values.

Each of the tables I want to open end with "_Enrollment" and the names in the combo box are like "James_Madison" and "Franklin"

Can anybody help me tweak this a bit to get it work? Thanks
-----


Dim comboElemen As Variant
Dim frmEnrollment_Forecast As Form


comboElemen = Form!frmEnrollment_Forecast!comboElementary

Set rst = dbs.OpenRecordset("'& comboElemen& '_Enrollment ", dbOpenDynaset)
 
Hi pvsmith5,

Provided your Form is open, you should pick up the value of your combo, and if I understand correctly, you are just not building your string correctly ..

[blue]
Code:
Set rst = dbs.OpenRecordset(comboElemen & "_Enrollment ", dbOpenDynaset)
[/blue]Incidentally, you have a seemingly redundant declaration ..

Code:
Dim frmEnrollment_Forecast As Form
.. as the name in the assignment statement references the Form by name not by reference to any variable.




Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Is this code line correct?

comboElemen = Form!frmEnrollment_Forecast!comboElementary

The variables I want to pass to the comboElemen are the values from the combo box.
 
Hi pvsmith5,

No! It should be
Code:
comboElemen = Form[red][b]s[/b][/red]!frmEnrollment_Forecast!comboElementary
assuming you want the value from combo "comboElementary" on form "frmEnrollment_Forecast"



Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks. I knew it had to be something I was just overlooking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top