My query prompts for cbo_EmployeeName and cbo_ClientName. So if I set the
RecordSource Property of the main form to the query it prompts me at
the
form's open. OK..for experimental purposes I have eliminated the prompts
from the query and removed the code that sets it at forms open and
again
tried to open the form....same perplexing result. ("Cant open any more
databases") The comboboxes I was talking about are not in the subform they
are on the main form.
Nothing with aggregate functions in any of the queries or forms or
modules.
Could you remove the code that sets the RecordSouce, and just set it
in
the
property?
Anything in qry_Union_Single_Weekly_Monthly that uses domain aggregate
functions?
Hmm. Now you have a query as the rowsource for the combo, and the
combo
is
in the subform? If so, and there are 37 instances of this subform,
then
it
is loading 37 instances of the same query. That should work okay, but if
you
were loading hundreds of instances of the same query, you would have
to
work
around that by using a callback function as the RowSourceType for the
combo.
The callback function would load one array of the values when
initialized,
and would respond to the calls from the different combo instances in the
different subform instances by just supplying the value out of the array.
Before proceeding down that path, just verify that this is the
problem,
because callbacks are not the most obvious things if you have not worked
with them before. Remove the RowSource from the combo, and check that
this
solves the problem.
If it does, this is the kind of thing you will need:
Function ListEmpl(fld As Control, id As Variant, _
row As Variant, col As Variant, code As Variant) As Variant
' Purpose: To return a list of Employees for a combo.
' Rationale: Workaround for "Cannot open more tables" error, when
*many*
combos
' (perhaps 100) try to read directly from table/query.
' Arguments: As required to fill combo box.
' Usage: RowSourceType property of Combo.
Const MaxEntries = 256 'Max number of employees to cater for.
Dim rst As DAO.Recordset
Static iEntries As Integer ' Number of Employees found.
Static iInstances As Integer ' Number of currently opened
instances.
Static sEmpl(MaxEntries, 1) As String ' Array of EmplID and name.
Select Case code
Case acLBInitialize ' Initialize.
Set rst = CurrentDb().OpenRecordset("tblEmployee")
iEntries = 0
Do While iEntries < MaxEntries And Not rst.EOF
sEmpl(iEntries, 0) = rst![EmplID]
sEmpl(iEntries, 1) = rst![Surname] & ", " &
rst![FirstName]
iEntries = iEntries + 1
rst.MoveNext
Loop
rst.Close
iInstances = iInstances + 1
ListEmpl = True
Case acLBOpen ' Open.
ListEmpl = Timer
Case acLBGetRowCount ' Get rows.
ListEmpl = iEntries
Case acLBGetColumnCount ' Get columns.
ListEmpl = 2
Case acLBGetColumnWidth ' Get column width.
If col = 0 Then ListEmpl = 0 Else ListEmpl = 1440
Case acLBGetValue ' Get the data.
ListEmpl = sEmpl(row, col)
Case acLBEnd ' End.
iInstances = iInstances - 1
If iInstances < 1 Then
Erase sEmpl
iEntries = 0
End If
End Select
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Allen,
I do not have any of the situations you asked for.
The recordsource of the form is set when it opens:
Form.RecordSource = qry_Union_Single_Weekly_Monthly
The rowsource of the combobox is:
SELECT DISTINCTROW Employees.EmployeeID, [EmployeeLastname] & ", " &
[EmployeeFirstName] AS EmployeeFullName FROM Employees ORDER BY
[EmployeeLastname] & ", " & [EmployeeFirstName];
Okay: now we have a different problem: what is opening all these
databases,
and not closing them?
Are you using domain aggregate functions such as DLookup() in the
RecordSource of the form? In the RowSource of the combos? These don't
clean
up after themselves, and there is a replacement here that does
clean
up
(and
runs faster):
http://members.iinet.net.au/~allenbrowne/ser-42.html
Do you have code that opens recordsets (or opens databases) and
does
not
Close them AND set them to nothing? You need to explicitly close
everything
you open (but only what you open), and set all object variables to
Nothing
(preferably in the error recovery section so they are dereferenced
even
after an error).
Allen,
I have reworked my form and it still will not work over my network.
My
main
data tables are on the server. When running the forms on the server
everything works great...but on another machine using linked
tables..I
get
the error "Can not open any more databases" Looks like it processes
about
half of the subforms. Maybe I need to add text boxes at each
date
location
instead of using subforms. I can populate the textboxes with the
query
data
but I will not have a separate record to click on to open the
edit
record
form. Any more suggestions?