I'm trying to assign a list of Names to a combobox control in Access VBA.
My problem is that the output string of names is not correct.
Here is my code:
Private Sub command186_click()
Dim firstName As String
Dim lastName As String
Dim rst As Object
Dim rowSourceText As String
Dim fullName As String
Set rst = CurrentDb.OpenRecordset("Pool_Contact")
Do While Not rst.EOF
firstName = rst("FName").Value
lastName = rst("LName").Value
fullName = firstName + " " + lastName
rst.MoveNext
Loop
Forms(FrmDaysAvailable).Controls("Combo202").rowSource = fullName
Debug.Print fullName
End Sub
I know that the error is somewhere inside of my loop, where the variable fullName is written over by the second result.
how can I fix this loop to produce a string that looks like fullName , fullName, fullName ...
Thanks for all your help
This can be a lot simpler:
Forms(FrmDaysAvailable).Controls("Combo202").rowSource = _
"SELECT ID, FName & ' ' & LName FROM Pool_Contact"
Or
Forms!FrmDaysAvailable.Combo202.rowSource = _
"SELECT ID, FName & ' ' & LName FROM Pool_Contact"
Or
Me.Combo202.rowSource = "SELECT ID, FName & ' ' & LName FROM Pool_Contact"
Furthermore, use & not + to concatenate. Plus (+) will give you problems with nulls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With