Passing a control name to a called subroutine

P

Proko

Can someone help me out with the syntax for how to do this. I've never tried
this before and I just can't seem to crack it.

I click a button which takes a selected item from one combo box and puts it
in another combo box.

The on click event for the button is:
Call CBF_MoveRight(cbo_From, cbo_To) ' I'm trying to pass the actual
combo box names here

The called sub is:
CallCBF_MoveRight(FromCombo as ?????, ToCombo as ?????)

A line in the sub then tries to look at column 0 of the combo.
If Not IsNull ([FromCombo].[Column](0) then........but access appears to be
looking for a combo called "FromCombo" rather than "cbo_from"

I then try to requery both combos and I'm not sure of the syntax for that
either.

Me.FromCombo.Requery 'should behave as Me.cbo_from.Requery
Me.ToCombo.Requery 'should behave as Me.cbo_To.Requery

Any help would be greatly appreciated.
 
A

Allen Browne

Pass a reference to the actual combo, rather than its name.

You declare the function like this:
Public Function CallCGF_MoveRight(FromCombo As ComboBox, _
ToCombo As ComboBox)
and call it like this:
Call CallCGF_MoveRight(Me.Combo1, Me.Combo2)

If you may pass list boxes or other controls (not just combos), use As
Control instead of As ComboBox
 
P

Proko

Thanks Allen,
Without passing the name I am unable to requery the combos from within the
function. Is there another way?

Allen said:
Pass a reference to the actual combo, rather than its name.

You declare the function like this:
Public Function CallCGF_MoveRight(FromCombo As ComboBox, _
ToCombo As ComboBox)
and call it like this:
Call CallCGF_MoveRight(Me.Combo1, Me.Combo2)

If you may pass list boxes or other controls (not just combos), use As
Control instead of As ComboBox
Can someone help me out with the syntax for how to do this. I've never
tried
[quoted text clipped - 23 lines]
Any help would be greatly appreciated.
 
D

Dennis

You are OK the way you have called it. In your called sub all you need is

CallCBF_MoveRight(FromCombo as Control, ToCombo as Control)

You reference them just by the name FromCombo without any Me prefixes.
I have done this with checkboxes and can clear my checkbox from my called
function so combo boxes should work the same I would think.
 
A

Allen Browne

Because you have a reference to the combo, you can requery it.

Just use:
FromCombo.Requery
ToCombo.Requery
or whatever.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Proko said:
Thanks Allen,
Without passing the name I am unable to requery the combos from within the
function. Is there another way?

Allen said:
Pass a reference to the actual combo, rather than its name.

You declare the function like this:
Public Function CallCGF_MoveRight(FromCombo As ComboBox, _
ToCombo As ComboBox)
and call it like this:
Call CallCGF_MoveRight(Me.Combo1, Me.Combo2)

If you may pass list boxes or other controls (not just combos), use As
Control instead of As ComboBox
Can someone help me out with the syntax for how to do this. I've never
tried
[quoted text clipped - 23 lines]
Any help would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top