Help with list boxes

seanog2001

Registered User.
Local time
Today, 07:52
Joined
Jun 26, 2006
Messages
67
I a list of data in a list box and i want to be able to choose diiferent pieces from the list. How can i ref an individual record in the list box do you use

ME.Listboxname.value something like that im lookin to move pieces of data from one list box to another for printing

i can move all the records by using
Private Sub MoveAll_Click()
Dim strSQL1 As String

strSQL1 = "Update projects SET projects.Selected = Yes Where projects.Selected = No"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL1
DoCmd.SetWarnings True
Form.Refresh
End Sub

and i can move them all back by using

Private Sub RemoveAll_Click()
Dim strSQL2 As String

strSQL2 = "Update projects SET projects.Selected = NO Where projects.Selected = Yes"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL2
DoCmd.SetWarnings True
Form.Refresh
End Sub

Any idea on how to move an individual record?
 
Sean,

If you have a simple listbox, then you reference the "bound" column
by Me.Listboxname.

If it has more than one column, you have to use Me.Listboxname.Column(n)
where n goes from 0 to (# columns - 1).

If it is a multi-select listbox, you're gonna have to loop through it
to find the ones with:

Me.Listboxname.Selected = True

then you will use those ones.

If you are doing this for printing, you don't really have to move them
to another listbox, but regardless, you'll have to loop through one of
them to either construct the query for the report, or set the individual
rows in your table (Selected = Yes).

Need more info.

p.s. There have been samples in the Sample Database forum here that
deal with this topic

hth,
Wayne
 
You don't have to run through ALL of the listbox items to see if they are selected. There is an ItemsSelected collection within the listbox. I am posting code that I am using for an application that runs through and opens up files based on the user's selections (as a sample).

Code:
    Do Until intCount = Me.lstResults.ItemsSelected.Count
        If Not IsNull(Me.lstResults.Column(1)) Then
            ' sets the stack location
            strFolder = DLookup("FileLocation", "tblFileLocation")
            ' reads the patient name
            strPatientName = Me.lstResults.Column(1, Me.lstResults.ItemsSelected(intCount))
            ' reads the stack number for the document selected
            strStackID = Me.lstResults.Column(9, Me.lstResults.ItemsSelected(intCount))
            ' reads the file name
            strStackFileID = Me.lstResults.Column(6, Me.lstResults.ItemsSelected(intCount))
            ' reads the document type (.doc or .tif)
            strDocType = Me.lstResults.Column(8, Me.lstResults.ItemsSelected(intCount))
            ' reads the form type (Oly Prescription Form, etc.)
            strFormType = Me.lstResults.Column(2, Me.lstResults.ItemsSelected(intCount))
            ' reads the event date for the item selected
            dteEventDate = Me.lstResults.Column(3, Me.lstResults.ItemsSelected(intCount))
            ' reads the add date for the item selected
            dteAddDate = Me.lstResults.Column(4, Me.lstResults.ItemsSelected(intCount))
            ' builds the file path for the file to open
            strDocNamePath = strFolder & "\" & strStackID & "\" & strStackFileID
            ' for multiple items, if the item is a TIFF then user can open multiples.
            ' for Word documents, one at a time (unless users without IDM installed can
            ' open Word documents faster, if so I will recode this.
            If strDocType = ".tif" Then
                OpenFileName strDocNamePath, strDocType
            End If
        End If
        intCount = intCount + 1
    Loop
 

Users who are viewing this thread

Back
Top Bottom