Renaming a control at Runtime (VB6 SP5)

Hi,

I have a function which loops round all of the controls on a form. Where the control name matches a field in a table, some data gets loaded as the controls combo dropdown list.
This has always worked fine, however, a problem has recently reared its head:

Adding new records doesnt need to display contacts that have left the company in the dropdown, however, viewinghistoric data does!

I wrote the original function to be dynamic i.e. if control.name = rec.fields("controlname") then sql = rec.fields("combosql")
Therefore, the easiest way for me to get round this issue would be to rename the control.

Re: Renaming a control at Runtime (VB6 SP5)

I approached it from a different angle and solved the problem - i'll leave it here in case anyone else has the same issue.

'Im using the it-partners ITCombo control
Dim WithEvents Cmd1 As itgrid6.itCombo

Public sub Form_Load()
Dim ComboName As String
'Set what the combo control will be called, if a primarykeyid hasnt been set overwrite Comboname to select the alternate sql
ComboName = "ContactsWith"
If PrimaryKeyID = Empty Or IsNull(PrimaryKeyID ) Then ComboName = "ContactsWithout"

'Add a new control to the form called either ContactsWith or ContactsWithout depending what SQL is needed
Set Cmd1 = Controls.Add("itgrid6.itcombo", ComboName)
'Clone the existing control over the new one - this means the newly created control has the correct font etc
Cmd1.Clone ContactId 'This makes sure the new combo takes the font properties of the contactid combo
'This is my function that populates the combos. It loops all of the controls on the form and loads the dropdown list for any that match.
Call PopulateFormComboBoxes(Me.Name, Me)
'Clone the new control over the original control - this also clones the newly populated dropdown list.
ContactId.Clone Cmd1
'remove the extra control so it isn't picked up in the save function
Controls.Remove Cmd1.Name
Set Cmd1 = Nothing 'Clean up variable
end sub

That got me my combo that shows "deleted" contacts who have left the company if opening an existing record, but only shows active contacts if adding a new record.