Chage event to AfterUpdate

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi There
Have used following code kindly supplied by "xRoachx" and it works a treat,
but need it to work with AfterUpate and not Exit, can't do this with (Cancel
As Integer) and if I remove (Cancel As Integer) the code dosen't work.
Any clues what I am doing wrong?

Private Sub ListBoxName_Exit(Cancel As Integer)

Dim strList as String
Dim intLen as Integer
Dim varSelectedRecord as Variant

If Me.ListBoxName.ItemsSelected.Count > 0 Then
For Each varSelectedRecord In ListBoxName.ItemsSelected
strList = strList + ListBoxName.Column(1, varSelectedRecord) & ","
Next varSelectedRecord

intLen = Len(strList)
[FieldName] = Left(strList, intLen - 1)
strList = ""
End If

End Sub

ListBoxName = The name of your list box
FieldName = The name of the field where you want to store the information

This code builds a string, seperated by commas. For example, say the list
box contains the words one, two, three, four, five and only one, two are
selected. "one, two" (without quotes) would be stored in the field.

Cheers Ross
 
Hi There
Have used following code kindly supplied by "xRoachx" and it works a treat,
but need it to work with AfterUpate and not Exit, can't do this with (Cancel
As Integer) and if I remove (Cancel As Integer) the code dosen't work.
Any clues what I am doing wrong?

The AfterUpdate event has no Cancel argument. Since you're not trying
to cancel anything, simply use the AfterUpdate event (rather than
Exit); just don't include the (Cancel as Integer). What do you mean by
"doesn't work"?

The code builds strList and puts it in a form textbox named FieldName.
If you don't have a textbox named FieldName it will give you an error.
Did you adapt the code to your form, or just try to use it unmodified?


John W. Vinson[MVP]
 
Hi John
Had already done exactly as suggested and my my code had been adapted - it
works a treat with Exit, but dosent work with AfterUpdate.
My Code is :
Private Sub List275_AfterUpdate()
Dim strList As String
Dim intLen As Integer
Dim varSelectedRecord As Variant

If Me.List275.ItemsSelected.Count > 0 Then
For Each varSelectedRecord In List275.ItemsSelected
strList = strList + List275.Column(4, varSelectedRecord) & ","
Next varSelectedRecord

intLen = Len(strList)
[Text261] = Left(strList, intLen - 1)
strList = ""
End If

If Me.List275.ItemsSelected.Count > 0 Then
For Each varSelectedRecord In List275.ItemsSelected
strList = strList + List275.Column(8, varSelectedRecord) & ","
Next varSelectedRecord

intLen = Len(strList)
[Text266] = Left(strList, intLen - 1)
strList = ""
End If
Command269.SetFocus
End Sub
It does run through the code without error messages, but does not display in
the text boxes, as it does with Exit - bit of a brain ache, any more
suggestions.
Cheers Ross
 

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

Back
Top