clear listbox when record refresh (1 Viewer)

alvincgp

New member
Local time
Today, 15:00
Joined
Aug 1, 2013
Messages
9
I have a listbox in a form that is NOT bound to any table and how can I delete the listbox when I refresh my record?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,169
to blank the listbox:

me.list0=""

to delete each element:

for i = me.list0.listcount-1 to 0 step -1
me.list0.removeitem(i)
next
 

isladogs

MVP / VIP
Local time
Today, 22:00
Joined
Jan 14, 2017
Messages
18,186
Just to clarify, which of the following do you mean
1. clear the selection(s) made
or
2. delete the contents of the listbox

What type of listbox - single or multiselect? Is the row source a value list?
 

alvincgp

New member
Local time
Today, 15:00
Joined
Aug 1, 2013
Messages
9
in this form, I have a vba for selecting files outside access as attachment in outlook. the files selected will be input in the listbox.

I do not need the files to be recorded in the access, so whenever a user click for next or new record the listbox shall be cleared.

the listbox is a value list.
 

alvincgp

New member
Local time
Today, 15:00
Joined
Aug 1, 2013
Messages
9
hi arnelgp,

my refresh button is built with embedded macro on the On Click event.

is there anywhere I can code the vba the listbox event?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,169
create a public function in a Module
Code:
public function fnClearList(Byref lst As Listbox)
Dim i as integer
for i = lst.listcount-1 to 0 step -1
lst.removeitem(i)
next
end function
on the embedded macro Runcode your pulic function:
Code:
fnClearList([listboxNameOnTheForm])
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,169
you're welcome.
 

Users who are viewing this thread

Top Bottom