how to transfer items in several controls to a list box with a com

G

gbpg

how would I tranfer textboxes, comboboxes, and listboxes on a form to a
listbox that would keep all the info - which would go to report after?
 
A

Alex Dybenko

Hi,
do not completely understand what you need, but here how you can loop
through all textboxes and list/combo boxes


dim ctl as control

For Each ctl In me.Controls
Select Case ctl.ControlType
Case acTextBox
'add from textbox
case acListBox, acComboBox
'add from listbox/combo
End Select
Next ctl


--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
G

gbpg

Hi Alex:

I was trying to have the user choose equipment from a list box and then
transfer this over with a command button to another list box to save data
entry and prvent typing errors. I tried to use a subroutine from somewhere I
had seen but the code actually moves items from one table to another instead
of just copying. Essentially what goes into the end listbox(es) will be used
for a record like a shipping list so there is a record. I tried to use a
sample that used a table called Source and one called Destination and make it
work for a table called EmployeeListing to start with then I was going to
have the other controls also copy and add to the final destination.
Below is the code
Private Sub btnDeselect_Click()
Dim rsDestination As DAO.Recordset
Dim theBug As String

If Me.lbDestination.ItemsSelected.Count = 0 Then
Beep
Exit Sub
End If

Set rsDestination = Me.lbDestination.Recordset

For Each itm In Me.lbDestination.ItemsSelected
On Error Resume Next
theBug = Me.lbDestination.ItemData(0)
rsDestination.FindFirst ("Description = '" &
Me.lbDestination.ItemData(itm) & "'")
rsDestination.Edit
rsDestination!InSelectedList = False
rsDestination.Update
Next itm

Me.lbSource.Requery
Me.lbDestination.Requery
End Sub
------------------------
Private Sub btnDeselectAll_Click()

Dim rsDestination As DAO.Recordset

Set rsDestination = Me.lbDestination.Recordset
rsDestination.MoveFirst

Do While Not rsDestination.EOF
rsDestination.Edit
rsDestination!InSelectedList = False
rsDestination.Update
rsDestination.MoveNext
Loop

Me.lbSource.Requery
Me.lbDestination.Requery

End Sub
------------------------
Private Sub btnSelect_Click()
Dim rsEmployeeListing As DAO.Recordset
Dim theBug As String

If Me.lbEmployeeListing.ItemsSelected.Count = 0 Then
Beep
Exit Sub
End If

Set rsSource = Me.lbEmployeeListing.Recordset

For Each itm In Me.lbEmployeeListing.ItemsSelected
theBug = Me.lbEmployeeListing.ItemData(0)
rsSource.FindFirst ("Description = '" &
Me.lbEmployeeListing.ItemData(itm) & "'")
rsSource.Edit
rsSource!InSelectedList = True
rsSource.Update
Next itm

Me.lbEmployeeListing.Requery
Me.lbDestination.Requery
End Sub
-----------------
Private Sub btnSelectAll_Click()
Dim rsEmployeeListing As DAO.Recordset

Set rsSource = Me.lbEmployeeListing1.Recordset
rsEmployeeListing.MoveFirst

Do While Not rsEmployeeListing.EOF
rsEmployeeListing.Edit
rsEmployeeListing!InSelectedList = True
rsEmployeeListing.Update
rsEmployeeListing.MoveNext
Loop

Me.lbEmployeeListing1.Requery
Me.lbDestination1.Requery

End Sub
-------------------
Private Sub Form_Open(Cancel As Integer)
Dim theSQL As String
theSQL = "SELECT Description, InSelectedList FROM BooleanList WHERE "

Me.lbEmployeeListing2.RowEmployeeListing = theSQL & "NOT InSelectedList"
Me.lbDestination2.RowEmployeeListing = theSQL & "InSelectedList"
End Sub
 
A

Alex Dybenko

Hi,
well, can see where this code moves items, it just changes the flag. I think
you need to adjust listboxes rowsources, so in left one it will show all
records, and in right one - selected only, then it will look like copying

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
G

gbpg

Now that my internet is back...that is why I am asking. I do not know how to
do make the right copy only. Any suggestions?
 
Top