Default values for a multi-select?

G

Guest

Hi,

Does anybody know can I designate a default value, let's say 2 or 3 items
selected, for a multi-select listbox with row source bound to table? And if
I can't select multiple default values, at least 1 default value? And if I
can't select any default value, please let me down gently, because I'm really
wanting this to be true :(

Thank you.
 
P

Perry

Let me rephrase yr question:

Say you are MS Access, and a programmer let's you put multiple values
in one field. Which records do you need to update the table, Mr Access?

Krgrds,
Perry
 
J

Jeff Boyce

You've described "how" you want to do something (use multi-select listbox,
set multiple defaults, ...).

It may be that there's a way to do "what" you want to do, but you'll need to
tell us what that is, if you'd like our ideas.

What do you mean "row source bound to table"?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
A

AccessVandal via AccessMonster.com

Hi,

Go to the ListBox properties - in the "Other" Tab, select the property called
"Multi Select", change it to "Extended".

As for the Default value, go to the ListBox properties - Data tab - "Default
Value"
Not sure of what you want with the default.
 
G

Guest

Gee, I must not have explained it very well because nobody knows what I mean!

I have an unbound form used to filter a report with a multi-select listbox
using Allen Browne's code. Here is the form code

Private Sub cmdOk_Click()
On Error GoTo Err_Handler

If IsNull(Me.startDate) Then
MsgBox "Please enter a start date."
Exit Sub
End If

If IsNull(Me.EndDate) Then
MsgBox "Please enter an end date."
Exit Sub
End If

If Me.lstReg.ItemsSelected.Count = 0 Then
MsgBox "Please choose a region."
Exit Sub
End If

Me.Visible = False

'Purpose: Open the report filtered to the items selected in the list box.
'Author: Allen J Browne, 2004. http://allenbrowne.com
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

'strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptOsr_SS"

'Loop through the ItemsSelected in the list box.
With Me.lstReg
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Reg] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Region: " & Left$(strDescrip, lngLen)
End If
End If

'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

'DoCmd.Close acForm, "frmParamHot"

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub






As I said, the row source of my list box gets data from a table:
SELECT tRegions.RegID, tRegions.RegDescription FROM tRegions ORDER BY
tRegions.RegDescription;

What I mean by "default value" is when the form is opened, instead of having
to highlight 2 items, they would already show as selected because this will
be the most-used selection by users. Then the users only have to press OK
instead of clicking to select.
 
A

AccessVandal via AccessMonster.com

Hi,

Well…only if you have said that earlier.

Here’s something to try out. Put in the on open event of your form.

Dim i As Integer

For i = 0 To Me.List2.ListCount - 1
Select Case List2.ItemData(i)
Case 1, 2
List2.Selected(i) = True
Case Else
List2.Selected(i) = False
End Select
Next I

Where “Case 1,2†is the ID of the first column, in my case 1 and 2 is the
customer ID and DataType is number.
 
G

Guest

Ohmigosh, you are the best, AccessVandal!! Totally plug 'n play. You made my
day!!

:) :) :) :)

Thank you!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top