I don't know whether it's just that I've never found it, but I was surprised to see that listboxes and comboboxes don't have the .AddItem method in Access that they have in Excel and Word.
Here's the function I use to add an item to an Access Listbox or Combobox. I had written a DelListItem sub too, but it was fundamentally flawed, so I haven't included it here.
---
Sub AddListItem(lst As Control, S As String)
With lst
If (.ControlType = acComboBox) Or (.ControlType = acListBox) Then
If .RowSourceType = "Value List" Then
If .ListCount > 0 Then
.RowSource = .RowSource & "; " & S
Else
.RowSource = .RowSource & S
End If
End If
End If
End With
End Sub
---
Call this function using:
AddListItem lstName, "text string"
---
The next one is due to the annoying problem of having to set focus to textboxes or comboboxes to read or set the information in them. The first is used to get the text from a textbox, and is simply used by calling:
GetText ctrName
The second sets the text in a textbox. Use:
SetText ctrName, "text string"
---
Function GetText(ctr As Control) As String
With ctr
If (.ControlType = acTextBox) Or (.ControlType = acComboBox) Then
.SetFocus
GetText = .Text
End If
End With
End Function
---
Sub SetText(ctr As Control, txt As String)
With ctr
If (.ControlType = acTextBox) Or (.ControlType = acComboBox) Then
.SetFocus
ctr.Text = txt
End If
End With
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.