-----Original Message-----
Phil,
(as always, watch for line wrap)
You can use this Sub to put the data into the controls. The names of the
arguments can be *anything*, as long as you use them in the correct place in
the code.
Private Sub cboChange(i as integer, anystring as string, number1 as single,
number2 as single)
Me.Controls("txtHeading" & i) = anystring
Me.Controls("txtNoOfChar" & i) = number1
Me.Controls("txtCombocount" & i) = number2
End Sub
In this example i equals the index number of the controls you want to put
the data into. If you called this sub using
Call cboChange(4,"Hello World", 500, 1000)
4 is the number of the controls that will be changed:
txtHeading4 would contain "Hello World"
txtNoOfChar4 would contain 500
and txtCombocount4 would contain 1000
Note that i used anystring, number1 and number2. I could have used whatever,
andy and banana as long as I used them for the right controls. The sub
could/would look like:
Private Sub cboChange(i as integer, whatever as string, Andy as single,
Banana as single)
Me.Controls("txtHeading" & i) = whatever
Me.Controls("txtNoOfChar" & i) = Andy
Me.Controls("txtCombocount" & i) = Banana
End Sub
You would still call it like this:
Call cboChange(4,"Hello World", 500, 1000)
I almost forgot to explain the Me.Controls("txtHeading" & i). What ever
number 'i' is will be concatenated to txtHeading. So if i = 6, then
Me.Controls("txtHeading" & i)
evaluates to txtHeading6.
Now for the combo boxes.
In the AfterUpdate event of each of the 10 combo boxes should have
Call cboChange(4,"Hello World", 500, 1000)
in the sub.
The procedures will look like this:
Private Sub cbo1_Afterupdate()
Call cboChange(1,"Hello World", 500, 1000)
End Sub
Private Sub cbo2_Afterupdate()
Call cboChange(2,"Hello World", 500, 1000)
End Sub
..
..
..
..
Private Sub cbo10_Afterupdate()
Call cboChange(10,"Hello World", 500, 1000)
End Sub
I'm still not sure WHERE the data for the 3 text boxes are coming from, but
you said "When a new selection is made in the combo box I want to change the
data in the 3 text boxes assiciated with that combo box."
If the data is coming from columns in the combo box, the code for combo box
1 would be:
Private Sub cbo1_Afterupdate()
Call cboChange(1,[cbo1].Column(3), [cbo1].Column(4), [cbo1].Column(5))
End Sub
Maybe this will help you
Steve
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
Hi Steve,
I've answered your questions. Thanks.....
Phil
-----Original Message-----
I'm still confused.....
Could you give an example of the control names? It
looks
like hte combo
boxes are named cbo1, cbo2,... cbo10. What are the
names
of the associated
txtHeading1, txtHeading2, txtHeading3,... text box,char
txtNoOfChar1, txtNoOfChar2, txtNoOfChar3,... text box,
general number
txtComboCount1, txtComboCount2, txtComboCount3,... text
box, general number
What data do you expect in them?
I think you should be using the control's AfterUpdate event instead of the
OnChange event. The OnChange event fires for every keystroke - 5 letters = 5
OnChange events happening.
I agree after more testing
In the Sub cboChange() code, it looks like you have
three
controls - >
txtHeading, txtNoOfChar and txtComboCount. If you set txtHeading to Null and
txtNoOfChar = 0,
they won't change no matter how many times you run the
sub.
In more testing I discovered that I want to set txtHeading
to "" not null
Where is the data for the arguments txtComboCount1, txtNoOfChar1 &
txtHeading1 coming from?
These are fields on my form.
I have 10 set of these fields and I figure that using a
subroutine would be the best way to update the related
fields in each set rather than repeating the code 10
times. I'm starting to think the repeated code would be
the best way.
cboChange([cbo1].Column(2), txtComboCount1, txtNoOfChar1, txtHeading1)
Steve
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
:
Hi again,
Sorry, I don't know how but this message was sent twice
before I had it finished. This is the completed message.
-----Original Message-----
Hi,
I posted this yesterday and didn't recive a
response.
I
thought that my question wasn't very clear, so I'm trying
again. I'm stuck until I can resolve this problem.
I have 10 sets of fields on a form and each set has a
combo box and 3 text fields. The fields in the 10 sets
are named the save except the last character is a 1, 2,
3, ... 10. When a new selection is made in the
combo
box
I want to change the data in the 3 text boxes assiciated
with that combo box.
This is my on-change event for the combo box in set number
1:
Private Sub cbo1_Change()
Call cboChange([cbo1].Column(2), txtComboCount1,
txtNoOfChar1, txtHeading1)
End Sub
Note: ([cbo1].Column(2) is a number associated with the
combo box. The 3rd field of the combo box.
This is my subroutine:
Private Sub cboChange(cboCount, txtComboCount,
txtNoOfChar, txtHeading)
txtHeading = Null
txtNoOfChar = 0
txtComboCount = cboCount
End Sub
My problem is that the values on the form do not change
and I don't know why. If I trace the code the code is
processed but the fields don't change.
I need to do the same type of thing for another
field
on
the form, but if I can get one to work I can figure out
the other.
Any Help?
Thanks,
Phil
.
.