I am pounding my head on the desk. So when I use the following code IN the Form that the controls are in I get a "Type Mismatch" Error. But if I move it to a Module, it works fine. I much rather load the combobox array (there are 15 comboboxes being loaded). Although they all are loaded with the same "list" the "list can change (so I can't just input the list in the properties list) depending on what the user selects. But all of that doesn't matter as the error is where this line of code is being located.
This code does NOT work (I have simplified it because i use very long variables, and there are other controls on the Form that impact the code, but again the code works, but not in the Form, only in a separate module as I will explain, but I would like the code in the form if i can. And I have tried using Me.Controls, same error.
I am using the term RECORDSET to represent the actual code that extracts the data from the Recordset from the DB. That part works fine too.
Code:
For comboboxindex = 1 To 15
BrandIndex = 0
Do
if RECORDSET.EOF then exit do
AddBrand(BrandIndex) = RECORDSET
comboBrandName = "ComboBoxBrand" & comboboxindex
Form_AddInvoice.controls(comboBrandName).additem (AddBrand(BrandIndex)), BrandIndex
BrandIndex = BrandIndex + 1
RECORDSET.MoveNext
Loop
RECOREDSET.MoveFirst
Next comboboxindex
Now when I make THIS change it works:
Code:
For comboboxindex
BrandIndex = 0
Do
if RECORDSET.EOF then exit do
AddBrand(BrandIndex) = RECORDSET
comboBrandName = "ComboBoxBrand" & comboboxindex
CALL UPDATEINVOICE
BrandIndex = BrandIndex + 1
RECORDSET.MoveNext
Loop
RECOREDSET.MoveFirst
Next comboboxindex
***********************************************
And this is a MODULE and NOT in the form..Also note All of the variables in this module are Global for the entire Project.
UPDATE INVOICE:
Form_AddInvoice.controls(comboBrandName).additem (AddBrand(BrandIndex)), BrandIndex
So what am I doing wrong. How can I rework the code so it's all in one place? Thanks again!
Ken L