Listbox returning numeric value not string

  • Thread starter Scott Whetsell, A.S. - WVSP
  • Start date
S

Scott Whetsell, A.S. - WVSP

I have a multiselect listbox that lists all users in my MDW file. After
making selections and submitting my form, the values that were selected are
not the text strings displayed in the lisbox, but rather numeric values.

How do I return the text string?
 
K

Klatuu

If you have multiple columns in your list box, you can return the correct
value by identifying the column you want. If the text is in say column 2,
you would use
Me.MyListBox(1)
Column numbers for a list box start at 0.
 
S

Stuart McCall

"Scott Whetsell, A.S. - WVSP"
I have a multiselect listbox that lists all users in my MDW file. After
making selections and submitting my form, the values that were selected
are
not the text strings displayed in the lisbox, but rather numeric values.

How do I return the text string?

You obtain it from the listbox's ItemData collection, using the index (the
numeric value you mentioned) :

With Me.listbox '<- Replace this with your control name
For i = 0 To .ItemsSelected.Count
Debug.Print .itemData(.ItemsSelected(i))
Next
End With
 
S

Scott Whetsell, A.S. - WVSP

As best as I can tell it should be just one column. My listbox is populated
by code to read the users in the mdw file. The code I used was provided by
Joan Wild:

Dim wrk As Workspace
Dim strUserName As String
Dim usr As User

Set wrk = DBEngine(0)
For Each usr In wrk.Users
If usr.Name <> "Admin" Then
strUsername = strUserName & ";" & usr.Name
End If
Next

Me.MsgRecipients.RowSource = strUserName

Set wrk = Nothing
 
D

Douglas J. Steele

In that case, what's the code you're using to do the selection?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Scott Whetsell, A.S. - WVSP"
 
S

Scott Whetsell, A.S. - WVSP

Here is the code attached to my submit button to get the selected recipients.

With Me.MsgRecipients
For Each varItem In .ItemsSelected
rst.AddNew
rst![CM_Date] = Format(Date, "yyyy-mm-dd")
rst![CM_Time] = Format(Time(), "Short Time")
rst![CM_From] = CurrentUser()
rst![CM_To] = varItem
rst![CM_Subject] = UCase(Me.MsgSubject)
rst![CM_Message] = UCase(Me.MsgDetails)
rst![CM_Priority] = strPri
rst![CM_Status] = "UNREAD"
rst.Update
Next varItem
End With
 
D

Douglas J. Steele

varItem is simply a pointer to which row is selected.

Replace

rst![CM_To] = varItem

with

rst![CM_To] = .ItemData(varItem)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Scott Whetsell, A.S. - WVSP"
Here is the code attached to my submit button to get the selected
recipients.

With Me.MsgRecipients
For Each varItem In .ItemsSelected
rst.AddNew
rst![CM_Date] = Format(Date, "yyyy-mm-dd")
rst![CM_Time] = Format(Time(), "Short Time")
rst![CM_From] = CurrentUser()
rst![CM_To] = varItem
rst![CM_Subject] = UCase(Me.MsgSubject)
rst![CM_Message] = UCase(Me.MsgDetails)
rst![CM_Priority] = strPri
rst![CM_Status] = "UNREAD"
rst.Update
Next varItem
End With

Douglas J. Steele said:
In that case, what's the code you're using to do the selection?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Scott Whetsell, A.S. - WVSP"
 
S

Scott Whetsell, A.S. - WVSP

Thanks Douglas, very simple yet effective fix.

Douglas J. Steele said:
varItem is simply a pointer to which row is selected.

Replace

rst![CM_To] = varItem

with

rst![CM_To] = .ItemData(varItem)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Scott Whetsell, A.S. - WVSP"
Here is the code attached to my submit button to get the selected
recipients.

With Me.MsgRecipients
For Each varItem In .ItemsSelected
rst.AddNew
rst![CM_Date] = Format(Date, "yyyy-mm-dd")
rst![CM_Time] = Format(Time(), "Short Time")
rst![CM_From] = CurrentUser()
rst![CM_To] = varItem
rst![CM_Subject] = UCase(Me.MsgSubject)
rst![CM_Message] = UCase(Me.MsgDetails)
rst![CM_Priority] = strPri
rst![CM_Status] = "UNREAD"
rst.Update
Next varItem
End With

Douglas J. Steele said:
In that case, what's the code you're using to do the selection?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Scott Whetsell, A.S. - WVSP"
As best as I can tell it should be just one column. My listbox is
populated
by code to read the users in the mdw file. The code I used was
provided
by
Joan Wild:

Dim wrk As Workspace
Dim strUserName As String
Dim usr As User

Set wrk = DBEngine(0)
For Each usr In wrk.Users
If usr.Name <> "Admin" Then
strUsername = strUserName & ";" & usr.Name
End If
Next

Me.MsgRecipients.RowSource = strUserName

Set wrk = Nothing



:

If you have multiple columns in your list box, you can return the
correct
value by identifying the column you want. If the text is in say
column
2,
you would use
Me.MyListBox(1)
Column numbers for a list box start at 0.
--
Dave Hargis, Microsoft Access MVP


:

I have a multiselect listbox that lists all users in my MDW file.
After
making selections and submitting my form, the values that were
selected
are
not the text strings displayed in the lisbox, but rather numeric
values.

How do I return the text string?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top