J
James Hallam
This should be really easy but I am at a loss!
What I have...
8 comboboxes labelled Company1, Company2 etc thru to Company8
I have a piece of code which will fill each combobox with some data
from an excel spreadsheet, this works fine. The code is repeated 8
times, for each combobox.
The working code:
With company
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
UserForm1.Company1.ColumnCount = comp.Fields.Count
UserForm1.Company1.Column = comp.GetRows(NoOfRecords)
What I would like to do is to change the code so I can loop it round 8
times, once for each combobox. this is the code I have tried, but I
won't work...
Dim i As Integer
Dim sref As String
Dim ref As Object
Dim ref2 As Object
For i = 1 To 8
With comp
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
sref = "UserForm1.Company" & i
Set ref = sref
ref.ColumnCount = comp.Fields.Count
Set ref2 = "UserForm1.Company" & i
ref2.Column = comp.GetRows(NoOfRecords)
Next i
Neither ref or ref2 work.
I came to the conclusion that I would need use a pointer (which I
assume the set command is used for in VBA). Any ideas why I can't set
a point with a string?
Any help would be appreiated
What I have...
8 comboboxes labelled Company1, Company2 etc thru to Company8
I have a piece of code which will fill each combobox with some data
from an excel spreadsheet, this works fine. The code is repeated 8
times, for each combobox.
The working code:
With company
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
UserForm1.Company1.ColumnCount = comp.Fields.Count
UserForm1.Company1.Column = comp.GetRows(NoOfRecords)
What I would like to do is to change the code so I can loop it round 8
times, once for each combobox. this is the code I have tried, but I
won't work...
Dim i As Integer
Dim sref As String
Dim ref As Object
Dim ref2 As Object
For i = 1 To 8
With comp
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
sref = "UserForm1.Company" & i
Set ref = sref
ref.ColumnCount = comp.Fields.Count
Set ref2 = "UserForm1.Company" & i
ref2.Column = comp.GetRows(NoOfRecords)
Next i
Neither ref or ref2 work.
I came to the conclusion that I would need use a pointer (which I
assume the set command is used for in VBA). Any ideas why I can't set
a point with a string?
Any help would be appreiated