Question : Insert values in listbox to access table

Hello Experts,

I have a query regarding how i can do the below.
I have a list box on the whose row source is a query. This is a read only form where user cannot edit any details of the record but can delete the record.
What i want to do is that on clicking the delete button the follwing happens:
the items in the list box are added to a table(tableone)
then these same values are deleted from the source table (tabletwo)
Is there any way i can accomplish the above in a fucntion that i can later call?

Thanks for all the help.

D

Answer : Insert values in listbox to access table

Write a function to loop through the values in your listbox and update the tables accordingly:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Private Sub ListBoxFunctionk(lstBox As ListBox)
 
    'Declare and initialize variables
    Dim i As Integer
    Dim strSQL As String
    
    'Make sure the listbox has something in it
    If Nz(lstBox, "") <> "" Then                                                    
      'Loop through the list items
     For i = 0 To lstBox.ListCount - 1
     
	'SQL to update table 1
	strSQL = "" 'write your insert statment here
	currentdb.execute strSQL
		
	'SQL to delete from table2
	strsql = "" 'write your delete statement here
	currentdb.execute strSQL
 
      Next i
 
    End If
 
End sub
Random Solutions  
 
programming4us programming4us