Also wonder why data that already exists is being duplicated. Sounds like underlying table design issue.
Regardless, will say that if you knew you'd be doing this from the outset, then you could have added the column number to the control name and shorten the code to something kind of like
Code:
Private Sub cboItemNo_Change()
Dim ctl As Control
Dim int As Integer
For Each ctl in Me.Controls
If ctl.ControlType = acTextbox Then
int = Right(ctl.Name,1)
.ctl = Nz(.cboItemNo.Column(int),"")
End If
Next
End Sub
If the first control name encountered ended in 4, the Right function would set int = 4. Then the value gets set to what's in column 4. If there's no value in it, then control is set to empty string. You could use any allowable alternate value for Nz. If you had a bunch of other textboxes, they wouldn't get a number at the end of their name.
Note: I would never start a name with a number. I also see that the absence of a number or numbers greater than 9 would have to be dealt with, but seeing as how this won't get used anyway, will leave it as is. Just thought it might be food for future thought. Upon further reflection, using the control tag would be even simpler.
Last edited by Micron; 03-14-2019 at 10:08 PM.
Reason: code correction & added info
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.