List Box Contents as Text (1 Viewer)

D

dennis g

Guest
I have a bit of code that writes an event log whenever a user updates a certain field. One the same form, there is a multiselect listbox where the user selects the different destinations the message will be printed to. I want to capture these selections and add them to the event log text, so I have proof of where a report was sent. My code so far:

Private Sub history_AfterUpdate()

Dim vItem As Variant
Dim evtTxt As String
Dim ctlList As Control

Set ctlList = Forms!nu_military!List63

For Each vItem In Me.List63.ItemsSelected
If Not IsNull(Me.List63.ItemData(vItem)) Then

'this is where I'm stuck' I need to enumerate 'the choices and grab all of them and store 'them in a string

End If
Next

If Not IsNull(event_log) Then event_log = event_log & vbCrLf
event_log = event_log & "This record was updated " & Now() & " by " & atCNames(1) & " " & evtTxt
End Sub

Any help is much appreciated.
 

BukHix

Registered User.
Local time
Today, 13:08
Joined
Feb 21, 2002
Messages
379
I am not sure I totaly understand what you are trying to do but maybe this will help. I put a list box and a text box on a form. When items in the list box are selected/deselected they are added or removed from the textbox. Am I on the right track?

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim getString As String
Dim i As Integer

Set frm = Forms!form1
Set ctl = frm!lstItemBox

For Each varItem In ctl.ItemsSelected

getString = getString & " " & ctl.Column(i, varItem) & ", "
Next varItem

Me.txtGetdata = getString
 
D

dennis g

Guest
Yes, you are. I actually solved this thing about midnight last night. The code I ended up with is:

Private Sub Text4_AfterUpdate()
Dim varItem As Variant
Dim strWhere As String

For Each varItem In Me!List0.ItemsSelected
strWhere = strWhere & Chr(39) & Me![List0].Column(1, varItem) & Chr(39) & " And "
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 4)


If Not IsNull(Text2) Then Text2 = Text2 & vbCrLf
Text2 = Text2 & "This record was updated " & Now() & " and was printed to" & " " & strWhere
End Sub

I put this code in the AfterUpdate section of the field that will be updated. It writes an event log to another field that shows when the item was updated and what printers it as sent to (network printers). I'm adding the user id code now so it also shows the user id that updated the file.

Thanks for the reply, I'm starting to get a little more sure of this stuff, so maybe I jumped the gun on asking for help.
 

BukHix

Registered User.
Local time
Today, 13:08
Joined
Feb 21, 2002
Messages
379
No problem. I didn't get the email until this morning and didn't work it out until I got settled in. Anyway I am glad you got it working.
 

Users who are viewing this thread

Top Bottom