#1 - Did you try setting the recordsource to Nothing?
#2 - I am not sure you need to pass the whole control.
Here is some sample code:
A Multi-Select ListBox can not be used directly in the Query Grid Criteria.
e.g. Forms![FormName]![ListBoxName] will NOT work.
Why?
Simply examine the output of the Selection and you will see that the string
produced is different from the one the Query Grid requires:
"MyText1 Or MyText2 Or MyText3" from Listbox
"MyText1" Or "MyText2" Or "MyText3" from query grid.
The solution to the multi-select listbox problem is to write the query in
code so that it looks the same way the query grid does.
Build the criteria based on selected values that you can determine by
looping through the selected property of the list box.
I usually write the query in the Grid and use multiple criteria and then
copy the SQL to code and work it into this format:
Private Sub btnCreateInvoice_Click()
On Error GoTo Err_btnCreateInvoice_Click
Dim frm As Form, ctl As Control, varItm As Variant, strCriteria As
String
Dim dbs As Database, qdf As QueryDef
Set dbs = CurrentDb
Set frm = Forms![CreateInvoiceData]
Set ctl = frm!ListPOs
strCriteria = ""
For Each varItm In ctl.ItemsSelected
strCriteria = strCriteria & "(pohdr.ponumber)='" &
Trim(ctl.ItemData(varItm)) & "' Or "
Next varItm
If strCriteria = "" Then
MsgBox "Select one or more PO's."
Exit Sub
End If
strCriteria = Left(strCriteria, Len(strCriteria) - 4)
strSQL = "SELECT [invnumber], Date() AS invdate, pohdr.vendno "
strSQL = strSQL & "FROM pohdr INNER JOIN poln ON pohdr.pokey =poln.pokey
"
strSQL = strSQL & "WHERE (" & strCriteria & ");"
If QueryExists("Inv1") = True Then
dbs.QueryDefs.Delete "Inv1"
End If
Set qdf = dbs.CreateQueryDef("Inv1")
qdf.SQL = strSQL
Set ctl = Nothing
Set frm = Nothing
Set dbs = Nothing
Exit_btnCreateInvoice_Click:
Exit Sub
Err_btnCreateInvoice_Click:
MsgBox ("Error # " & str(Err.Number) & " was generated by " & Err.Source
& Chr(13) & Err.Description)
Resume Exit_btnCreateInvoice_Click
End Sub
Function QueryExists(strQueryName As String) As Boolean
On Error Resume Next
QueryExists = IsObject(CurrentDb.QueryDefs(strQueryName))
End Function
To de-select all items in a list box try:
Dim lngX As Long
With Me![lstMyListBox]
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
End With
#3 -
For older versions of Access try this:
http://www.mvps.org/access/api/api0001.htm
This code is a new feature in Access 2002.
It allows you to browse for a file and then store the selected file in 2
text boxes:
Me![txtLocalDir] , Me![txtLocalFileName]
'1 = DialogOpen, 2= SaveAs, 3=FilePicker, 4 = FolderPicker
'Cannot be used in Access 2000!
With Application.FileDialog(3)
.AllowMultiSelect = False
If .Show = True Then
Me![lblEdit].Visible = True
Me![txtLocalDir] = Left$(.SelectedItems(1),
InStrRev(.SelectedItems(1), "\"))
Me![txtLocalFileName] = Right$(.SelectedItems(1),
Len(.SelectedItems(1)) - InStrRev(.SelectedItems(1), "\"))
Me![txtLocalFileName].SetFocus
End If
End With
========================================
--
Joe Fallon
Access MVP
Sacred said:
Okay, I am going nuts. I am so use to web programming(asp,asp.net,vb.net,
vbscript) and now I need to develop an application for someone using ACCESS
front end.
Basically I have a few questions:
1) How to clear(as in remove the items) the *entire* listbox. For
instance I have tried lst.clear but that is not a valid function. Right now
I am removing them one by one via the removeitem. Is there a way to
completely clear it without looping it myself?
2) How to pass a control to a sub procedure. For instance item number one
I was trying to make that a sub procedure where you could pass it any
listbox and it would go through and remove the items. However, everytime I
try to pass the list box control to the subroutine it tells me "Object
required" when debugging I look at the code and the Object itself is set to
NULL because nothing has been selected in the listbox. Is there a way to
pass the *entire control* to a sub procedure? i ahve tried byRef and that
doesn't seem to work either. How I am passing it is Me.Listbox and the
parameter has been set to either byRef box as control or byRef box as
object. I have even tried byval but no dice. I imagine it is becuase it
thinks it Null in value. Which it is not. Becuase there are items listed
there in the box
3) I read somewhere that if you develop a mde file that you can not use
filedialog control that comes from the office reference 10.0 library. Is
there another filedialog control I cna use. I couldn't find one to use in
access library itself.