requery vs. refresh vs. Remove Filter/Sort

D

Dirk Goldgar

rgrantz said:
Interesting and very frustrating problem:

I have a form w/ unbound controls in the Header; the values of these
controls are the parameters of the query that produces the records in
the Details section. All of the parameters in the query are:

Like [Forms]![FormName]![UnboundFormControlName] & "*"

2 of the unbound controls are comboboxes with a list source of
queries that are employee numbers from specific departments. I have
the OnChange event set to fire the Me.Requery procedure. The 3rd
combobox has a list source of a table (customer number and associated
name). I can't use the OnChange on this one, because I need it to
auto-expand as user types customer name.

The problem:

The 2 employee comboboxes work great. However, no matter what I do,
I can't get the records to refresh and show the new recordset using
the CUSTOMER combobox. Putting me.requery in the after update, or
even on a separate command button after customer list is chosen, will
not refresh the records. The only way to refresh them and show the
new recordset after the customer name is changed is to go the records
menu and choose "remove filter/sort." The other 2 comboboxes work
great; when I remove filter/sort, the records reflect the customer
name in the combobox (and the existing values in the other 2
comboboxes), and I can continue to change the recordset from there
using the OTHER 2 comboboxes, but once customer name is changed, I
need to choose Records-->Remove filter/Sort, which then refreshes to
show data for new customer name and the other 2 comboboxes.

Can anyone explain this? I can email this DB to someone if you want
to see this. It seems EXTREMELY weird to me.


Thanks for any help or ideas. Using Access 2000 (updated) w/ Windows
2000 Pro (updated)

You shouldn't use the Change event of a combo box for this sort of
thing, for the reason that you've discovered. The AfterUpdate event is
what you should normally use, so I don't understand why it isn't working
for you. Please post the SQL of the form's recordsource, as well as the
code you have in the CUSTOMER combo box's AfterUpdate event and any
other events associated with that combo box. Also post the rowsource of
the combo box, its ColumnCount property, and its BoundColumn property
(as displayed on the property sheet).
 
R

rgrantz

Interesting and very frustrating problem:

I have a form w/ unbound controls in the Header; the values of these
controls are the parameters of the query that produces the records in the
Details section. All of the parameters in the query are:

Like [Forms]![FormName]![UnboundFormControlName] & "*"

2 of the unbound controls are comboboxes with a list source of queries that
are employee numbers from specific departments. I have the OnChange event
set to fire the Me.Requery procedure. The 3rd combobox has a list source of
a table (customer number and associated name). I can't use the OnChange on
this one, because I need it to auto-expand as user types customer name.

The problem:

The 2 employee comboboxes work great. However, no matter what I do, I can't
get the records to refresh and show the new recordset using the CUSTOMER
combobox. Putting me.requery in the after update, or even on a separate
command button after customer list is chosen, will not refresh the records.
The only way to refresh them and show the new recordset after the customer
name is changed is to go the records menu and choose "remove filter/sort."
The other 2 comboboxes work great; when I remove filter/sort, the records
reflect the customer name in the combobox (and the existing values in the
other 2 comboboxes), and I can continue to change the recordset from there
using the OTHER 2 comboboxes, but once customer name is changed, I need to
choose Records-->Remove filter/Sort, which then refreshes to show data for
new customer name and the other 2 comboboxes.

Can anyone explain this? I can email this DB to someone if you want to see
this. It seems EXTREMELY weird to me.


Thanks for any help or ideas. Using Access 2000 (updated) w/ Windows 2000
Pro (updated)
 
D

Dirk Goldgar

rgrantz said:
Thanks for the response. Below is the info requested:

SQL of recordsource (although I use the query builder):

SELECT ProductionData.EnteredBy, EmpList.EmpName,
ProductionData.DateRec, ProductionData.DateEntered,
ProductionData.ItemPartNum, ProductionData.PSNum,
ProductionData.CustNum, CustomerList.CustName, ProductionData.Status,
OrderStatusList.Status2, ProductionData.DateDes,
ProductionData.SqFoot, ProductionData.AutoDes, ProductionData.DesBy,
EmpList_1.EmpName, ProductionData.Notes, ItemData.ItemNum,
ItemData.DateProd, ItemData.Vendor, VendorList.VendorName,
ItemData.Wall, ItemData.Floor, ItemData.Bead, ItemData.MachineNum,
ItemData.ShiftProd, ItemData.OperatorNum, EmpList_2.EmpName,
ItemData.PartnerNum, EmpList_3.EmpName, ItemData.Verifier1Num,
EmpList_4.EmpName, ItemData.Verifier2Num, EmpList_5.EmpName,
ItemData.[2ndVerifier1Num], ItemData.[2ndVerifier2Num],
ItemData.TurnaroundDays, ItemData.Notes, [DateEntered]-[DateRec] AS
EntryTurn, [DateDes]-[DateEntered] AS DesignTurn,
[DateProd]-[DateDes] AS ProdTurn, [DateProd]-[DateEntered] AS
TotalTurn

FROM EmpList AS EmpList_4 RIGHT JOIN (EmpList AS EmpList_3 RIGHT JOIN
(CustomerList RIGHT JOIN (OrderStatusList RIGHT JOIN (VendorList
RIGHT JOIN (EmpList AS EmpList_5 RIGHT JOIN (EmpList AS EmpList_2
RIGHT JOIN (EmpList AS EmpList_1 RIGHT JOIN (EmpList RIGHT JOIN
(ItemData RIGHT JOIN ProductionData ON ItemData.PSNum =
ProductionData.PSNum) ON EmpList.EmpID = ProductionData.EnteredBy) ON
EmpList_1.EmpID = ProductionData.DesBy) ON EmpList_2.EmpID =
ItemData.OperatorNum) ON EmpList_5.EmpID = ItemData.Verifier2Num) ON
VendorList.VendorID = ItemData.Vendor) ON OrderStatusList.ID =
ProductionData.Status) ON CustomerList.CustID =
ProductionData.CustNum) ON EmpList_3.EmpID = ItemData.PartnerNum) ON
EmpList_4.EmpID = ItemData.Verifier1Num

WHERE (((ProductionData.EnteredBy) Like
[Forms]![frmMainReport]![JREnteredBy] & "*") AND
((ProductionData.CustNum)=[Forms]![frmMainReport]![JRCustNum]) AND
((ProductionData.DesBy) Like [Forms]![frmMainReport]![JRDesBy] & "*")
AND
(([DateEntered]-[DateRec])>=[Forms]![frmMainReport]![JREntryTurn])
AND (([DateDes]-[DateEntered])>=[Forms]![frmMainReport]![JRDesTurn])
AND (([DateProd]-[DateDes])>=[Forms]![frmMainReport]![JRProdTurn])
AND
(([DateProd]-[DateEntered])>=[Forms]![frmMainReport]![JRTotalTurn]))
OR ((([Forms]![frmMainReport]![JRCustNum]) Is Null));

As you may have guessed, the multiple EmpName and EmpList entries are
using one Employee List table to show names for employee numbers, or
to show specific department employees in the criteria drop-downs.
The "Like [formfield] & *" is to return all records in that field
even when no value is chosen (ie. no criteria applied).

Row Source of Customer Combobox:

SELECT [CustomerList].[CustID], [CustomerList].[CustName] FROM
CustomerList;

Column Count: 2
Bound Column: 1
AfterUpdate: Docmd.Requery (with the understood Sub/End Sub wrap in
the module window)


Since I posted that last problem, I've run into several more. It
seems my query's just getting too complex, as I have 7 unbound
controls with the AfterUpdates set to DoCmd.Requery, and the criteria
in the query pulling from these 7 separate unbound controls. I'm
getting extremely unpredictable results that simply are not adding
up. Is my placement of the Is Nulls and the Or Isnulls in the query
builder messed up? This form working correctly seems to depend on
the order in which I set the criteria in the form. You can see the
unbound controsl in the SQL, they are all the ones that express
criteria. I need to be able to allow for the calculated fields
having nulls (ie. DateProd. might be Null, so TotalTurn (turnaround
time from receipt of order to date produced) needs to be able to have
nulls.

Why isn't this working? Am I just trying to do to much on one form?
I can put this DB somewhere for download if people want to see the
weird behavior of this form.

I don't think we have any reason to believe that the query is too
complex. I do have a few questions and a suggestion. First, the
suggestion: where you have the VBA statement "Docmd.Requery", in you
AfterUpdate event procedures, change that to "Me.Requery". That is more
efficient, and eliminates any possibility that Access is getting
confused about exactly what needs to be requeried. If you have a
statement that requeries a specific control name with 'DoCmd.Requery
"<control name>"', change that to 'Me!<control name>.Requery'.

Questions:

1. You have repeatedly referred to the combo box in question as
"Customer". But the control reference in your query criterion is to
"[Forms]![frmMainReport]![JRCustNum]". Which is correct? If the combo
box is named "Customer", that's what your control reference should use.

2. I notice that the primary key field in table CustomerList is named
"CustID". Am I right in believing that in other tables, CustNum is the
name of the foreign key field that relates to CustID? It appears so
from the SQL, but I want to make sure.

3. You may well have your "OR Is Null" subclauses messed up. How do you
want to have this work? Do you want each of these criterion controls
ignored in the query's Where clause if the control is Null? If so, you
might try this (untested) revision of your WHERE clause:

WHERE
(ProductionData.EnteredBy Like
[Forms]![frmMainReport]![JREnteredBy] & "*")
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
AND
(ProductionData.DesBy Like
[Forms]![frmMainReport]![JRDesBy] & "*")
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
([Forms]![frmMainReport]![JREntryTurn] Is Null)
)
AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
([Forms]![frmMainReport]![JRDesTurn] Is Null)
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
([Forms]![frmMainReport]![JRProdTurn] Is Null)
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
([Forms]![frmMainReport]![JRTotalTurn] Is Null)
)


On the other hand, that may not be what you're after.
 
R

rgrantz

Thanks for the response. Below is the info requested:

SQL of recordsource (although I use the query builder):

SELECT ProductionData.EnteredBy, EmpList.EmpName, ProductionData.DateRec,
ProductionData.DateEntered, ProductionData.ItemPartNum,
ProductionData.PSNum, ProductionData.CustNum, CustomerList.CustName,
ProductionData.Status, OrderStatusList.Status2, ProductionData.DateDes,
ProductionData.SqFoot, ProductionData.AutoDes, ProductionData.DesBy,
EmpList_1.EmpName, ProductionData.Notes, ItemData.ItemNum,
ItemData.DateProd, ItemData.Vendor, VendorList.VendorName, ItemData.Wall,
ItemData.Floor, ItemData.Bead, ItemData.MachineNum, ItemData.ShiftProd,
ItemData.OperatorNum, EmpList_2.EmpName, ItemData.PartnerNum,
EmpList_3.EmpName, ItemData.Verifier1Num, EmpList_4.EmpName,
ItemData.Verifier2Num, EmpList_5.EmpName, ItemData.[2ndVerifier1Num],
ItemData.[2ndVerifier2Num], ItemData.TurnaroundDays, ItemData.Notes,
[DateEntered]-[DateRec] AS EntryTurn, [DateDes]-[DateEntered] AS DesignTurn,
[DateProd]-[DateDes] AS ProdTurn, [DateProd]-[DateEntered] AS TotalTurn

FROM EmpList AS EmpList_4 RIGHT JOIN (EmpList AS EmpList_3 RIGHT JOIN
(CustomerList RIGHT JOIN (OrderStatusList RIGHT JOIN (VendorList RIGHT JOIN
(EmpList AS EmpList_5 RIGHT JOIN (EmpList AS EmpList_2 RIGHT JOIN (EmpList
AS EmpList_1 RIGHT JOIN (EmpList RIGHT JOIN (ItemData RIGHT JOIN
ProductionData ON ItemData.PSNum = ProductionData.PSNum) ON EmpList.EmpID =
ProductionData.EnteredBy) ON EmpList_1.EmpID = ProductionData.DesBy) ON
EmpList_2.EmpID = ItemData.OperatorNum) ON EmpList_5.EmpID =
ItemData.Verifier2Num) ON VendorList.VendorID = ItemData.Vendor) ON
OrderStatusList.ID = ProductionData.Status) ON CustomerList.CustID =
ProductionData.CustNum) ON EmpList_3.EmpID = ItemData.PartnerNum) ON
EmpList_4.EmpID = ItemData.Verifier1Num

WHERE (((ProductionData.EnteredBy) Like
[Forms]![frmMainReport]![JREnteredBy] & "*") AND
((ProductionData.CustNum)=[Forms]![frmMainReport]![JRCustNum]) AND
((ProductionData.DesBy) Like [Forms]![frmMainReport]![JRDesBy] & "*") AND
(([DateEntered]-[DateRec])>=[Forms]![frmMainReport]![JREntryTurn]) AND
(([DateDes]-[DateEntered])>=[Forms]![frmMainReport]![JRDesTurn]) AND
(([DateProd]-[DateDes])>=[Forms]![frmMainReport]![JRProdTurn]) AND
(([DateProd]-[DateEntered])>=[Forms]![frmMainReport]![JRTotalTurn])) OR
((([Forms]![frmMainReport]![JRCustNum]) Is Null));

As you may have guessed, the multiple EmpName and EmpList entries are using
one Employee List table to show names for employee numbers, or to show
specific department employees in the criteria drop-downs. The "Like
[formfield] & *" is to return all records in that field even when no value
is chosen (ie. no criteria applied).

Row Source of Customer Combobox:

SELECT [CustomerList].[CustID], [CustomerList].[CustName] FROM CustomerList;

Column Count: 2
Bound Column: 1
AfterUpdate: Docmd.Requery (with the understood Sub/End Sub wrap in the
module window)


Since I posted that last problem, I've run into several more. It seems my
query's just getting too complex, as I have 7 unbound controls with the
AfterUpdates set to DoCmd.Requery, and the criteria in the query pulling
from these 7 separate unbound controls. I'm getting extremely unpredictable
results that simply are not adding up. Is my placement of the Is Nulls and
the Or Isnulls in the query builder messed up? This form working correctly
seems to depend on the order in which I set the criteria in the form. You
can see the unbound controsl in the SQL, they are all the ones that express
criteria. I need to be able to allow for the calculated fields having nulls
(ie. DateProd. might be Null, so TotalTurn (turnaround time from receipt of
order to date produced) needs to be able to have nulls.

Why isn't this working? Am I just trying to do to much on one form? I can
put this DB somewhere for download if people want to see the weird behavior
of this form.

Thanks again Dirk, and everyone.




Dirk Goldgar said:
rgrantz said:
Interesting and very frustrating problem:

I have a form w/ unbound controls in the Header; the values of these
controls are the parameters of the query that produces the records in
the Details section. All of the parameters in the query are:

Like [Forms]![FormName]![UnboundFormControlName] & "*"

2 of the unbound controls are comboboxes with a list source of
queries that are employee numbers from specific departments. I have
the OnChange event set to fire the Me.Requery procedure. The 3rd
combobox has a list source of a table (customer number and associated
name). I can't use the OnChange on this one, because I need it to
auto-expand as user types customer name.

The problem:

The 2 employee comboboxes work great. However, no matter what I do,
I can't get the records to refresh and show the new recordset using
the CUSTOMER combobox. Putting me.requery in the after update, or
even on a separate command button after customer list is chosen, will
not refresh the records. The only way to refresh them and show the
new recordset after the customer name is changed is to go the records
menu and choose "remove filter/sort." The other 2 comboboxes work
great; when I remove filter/sort, the records reflect the customer
name in the combobox (and the existing values in the other 2
comboboxes), and I can continue to change the recordset from there
using the OTHER 2 comboboxes, but once customer name is changed, I
need to choose Records-->Remove filter/Sort, which then refreshes to
show data for new customer name and the other 2 comboboxes.

Can anyone explain this? I can email this DB to someone if you want
to see this. It seems EXTREMELY weird to me.


Thanks for any help or ideas. Using Access 2000 (updated) w/ Windows
2000 Pro (updated)

You shouldn't use the Change event of a combo box for this sort of
thing, for the reason that you've discovered. The AfterUpdate event is
what you should normally use, so I don't understand why it isn't working
for you. Please post the SQL of the form's recordsource, as well as the
code you have in the CUSTOMER combo box's AfterUpdate event and any
other events associated with that combo box. Also post the rowsource of
the combo box, its ColumnCount property, and its BoundColumn property
(as displayed on the property sheet).

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

david epsom dot com dot au

Also, try
v = cbo.listcount
and
cbo.rowsource = cbo.rowsource

There are occasional problems where cbo's do not
refresh the parameters ([Forms]![frmMainReport]![JRCustNum])
when doing a refresh or requery. Using Listcount
or resetting the rowsource may overcome this kind
of problem.

(david)

Dirk Goldgar said:
rgrantz said:
Thanks for the response. Below is the info requested:

SQL of recordsource (although I use the query builder):

SELECT ProductionData.EnteredBy, EmpList.EmpName,
ProductionData.DateRec, ProductionData.DateEntered,
ProductionData.ItemPartNum, ProductionData.PSNum,
ProductionData.CustNum, CustomerList.CustName, ProductionData.Status,
OrderStatusList.Status2, ProductionData.DateDes,
ProductionData.SqFoot, ProductionData.AutoDes, ProductionData.DesBy,
EmpList_1.EmpName, ProductionData.Notes, ItemData.ItemNum,
ItemData.DateProd, ItemData.Vendor, VendorList.VendorName,
ItemData.Wall, ItemData.Floor, ItemData.Bead, ItemData.MachineNum,
ItemData.ShiftProd, ItemData.OperatorNum, EmpList_2.EmpName,
ItemData.PartnerNum, EmpList_3.EmpName, ItemData.Verifier1Num,
EmpList_4.EmpName, ItemData.Verifier2Num, EmpList_5.EmpName,
ItemData.[2ndVerifier1Num], ItemData.[2ndVerifier2Num],
ItemData.TurnaroundDays, ItemData.Notes, [DateEntered]-[DateRec] AS
EntryTurn, [DateDes]-[DateEntered] AS DesignTurn,
[DateProd]-[DateDes] AS ProdTurn, [DateProd]-[DateEntered] AS
TotalTurn

FROM EmpList AS EmpList_4 RIGHT JOIN (EmpList AS EmpList_3 RIGHT JOIN
(CustomerList RIGHT JOIN (OrderStatusList RIGHT JOIN (VendorList
RIGHT JOIN (EmpList AS EmpList_5 RIGHT JOIN (EmpList AS EmpList_2
RIGHT JOIN (EmpList AS EmpList_1 RIGHT JOIN (EmpList RIGHT JOIN
(ItemData RIGHT JOIN ProductionData ON ItemData.PSNum =
ProductionData.PSNum) ON EmpList.EmpID = ProductionData.EnteredBy) ON
EmpList_1.EmpID = ProductionData.DesBy) ON EmpList_2.EmpID =
ItemData.OperatorNum) ON EmpList_5.EmpID = ItemData.Verifier2Num) ON
VendorList.VendorID = ItemData.Vendor) ON OrderStatusList.ID =
ProductionData.Status) ON CustomerList.CustID =
ProductionData.CustNum) ON EmpList_3.EmpID = ItemData.PartnerNum) ON
EmpList_4.EmpID = ItemData.Verifier1Num

WHERE (((ProductionData.EnteredBy) Like
[Forms]![frmMainReport]![JREnteredBy] & "*") AND
((ProductionData.CustNum)=[Forms]![frmMainReport]![JRCustNum]) AND
((ProductionData.DesBy) Like [Forms]![frmMainReport]![JRDesBy] & "*")
AND
(([DateEntered]-[DateRec])>=[Forms]![frmMainReport]![JREntryTurn])
AND (([DateDes]-[DateEntered])>=[Forms]![frmMainReport]![JRDesTurn])
AND (([DateProd]-[DateDes])>=[Forms]![frmMainReport]![JRProdTurn])
AND
(([DateProd]-[DateEntered])>=[Forms]![frmMainReport]![JRTotalTurn]))
OR ((([Forms]![frmMainReport]![JRCustNum]) Is Null));

As you may have guessed, the multiple EmpName and EmpList entries are
using one Employee List table to show names for employee numbers, or
to show specific department employees in the criteria drop-downs.
The "Like [formfield] & *" is to return all records in that field
even when no value is chosen (ie. no criteria applied).

Row Source of Customer Combobox:

SELECT [CustomerList].[CustID], [CustomerList].[CustName] FROM
CustomerList;

Column Count: 2
Bound Column: 1
AfterUpdate: Docmd.Requery (with the understood Sub/End Sub wrap in
the module window)


Since I posted that last problem, I've run into several more. It
seems my query's just getting too complex, as I have 7 unbound
controls with the AfterUpdates set to DoCmd.Requery, and the criteria
in the query pulling from these 7 separate unbound controls. I'm
getting extremely unpredictable results that simply are not adding
up. Is my placement of the Is Nulls and the Or Isnulls in the query
builder messed up? This form working correctly seems to depend on
the order in which I set the criteria in the form. You can see the
unbound controsl in the SQL, they are all the ones that express
criteria. I need to be able to allow for the calculated fields
having nulls (ie. DateProd. might be Null, so TotalTurn (turnaround
time from receipt of order to date produced) needs to be able to have
nulls.

Why isn't this working? Am I just trying to do to much on one form?
I can put this DB somewhere for download if people want to see the
weird behavior of this form.

I don't think we have any reason to believe that the query is too
complex. I do have a few questions and a suggestion. First, the
suggestion: where you have the VBA statement "Docmd.Requery", in you
AfterUpdate event procedures, change that to "Me.Requery". That is more
efficient, and eliminates any possibility that Access is getting
confused about exactly what needs to be requeried. If you have a
statement that requeries a specific control name with 'DoCmd.Requery
"<control name>"', change that to 'Me!<control name>.Requery'.

Questions:

1. You have repeatedly referred to the combo box in question as
"Customer". But the control reference in your query criterion is to
"[Forms]![frmMainReport]![JRCustNum]". Which is correct? If the combo
box is named "Customer", that's what your control reference should use.

2. I notice that the primary key field in table CustomerList is named
"CustID". Am I right in believing that in other tables, CustNum is the
name of the foreign key field that relates to CustID? It appears so
from the SQL, but I want to make sure.

3. You may well have your "OR Is Null" subclauses messed up. How do you
want to have this work? Do you want each of these criterion controls
ignored in the query's Where clause if the control is Null? If so, you
might try this (untested) revision of your WHERE clause:

WHERE
(ProductionData.EnteredBy Like
[Forms]![frmMainReport]![JREnteredBy] & "*")
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
AND
(ProductionData.DesBy Like
[Forms]![frmMainReport]![JRDesBy] & "*")
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
([Forms]![frmMainReport]![JREntryTurn] Is Null)
)
AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
([Forms]![frmMainReport]![JRDesTurn] Is Null)
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
([Forms]![frmMainReport]![JRProdTurn] Is Null)
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
([Forms]![frmMainReport]![JRTotalTurn] Is Null)
)


On the other hand, that may not be what you're after.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

david epsom dot com dot au said:
Also, try
v = cbo.listcount
and
cbo.rowsource = cbo.rowsource

There are occasional problems where cbo's do not
refresh the parameters ([Forms]![frmMainReport]![JRCustNum])
when doing a refresh or requery. Using Listcount
or resetting the rowsource may overcome this kind
of problem.

I've heard this before -- maybe from you, David -- but I haven't seen it
myself. Can you give me a scenario to reproduce it? Is it specific to
a particular version of Access?

In this case, if I read the original message right, it's the form's
recordsource that is being requeried. Are you aware of a similar
problem in requerying the form?
 
D

david epsom dot com dot au

myself. Can you give me a scenario to reproduce it? Is it specific
a particular version of Access?

dunno.

There is a KB article somewhere about cbo's not refreshing
correctly when the cbo uses a cached copy of the binary
copy of the query, rather than rebuilding the query from
the sql, after a parameter value has changed.

Steven Lebans posted something somewhere about using ListCount
to force a cbo to complete its data query (like using MoveLast
before RecordCount)

In A97 I had code like this:
Me!cbo1.RowSource = fnRowSourceSQL()
Me.cbo1.Requery
DoCmd.Requery Me.cbo1
Which noticeably failed to do anything useful. A dummy function
inside the query proved that the query never ran until the
cbo list was 'dropped down' - the problem was fixed by using
..ListCount instead of .ReQuery.

(david)


Dirk Goldgar said:
david epsom dot com dot au said:
Also, try
v = cbo.listcount
and
cbo.rowsource = cbo.rowsource

There are occasional problems where cbo's do not
refresh the parameters ([Forms]![frmMainReport]![JRCustNum])
when doing a refresh or requery. Using Listcount
or resetting the rowsource may overcome this kind
of problem.

I've heard this before -- maybe from you, David -- but I haven't seen it
myself. Can you give me a scenario to reproduce it? Is it specific to
a particular version of Access?

In this case, if I read the original message right, it's the form's
recordsource that is being requeried. Are you aware of a similar
problem in requerying the form?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
R

rgrantz

Thanks again, below are details to questions/suggestions:

- I used docmd.requery because the me.requery for some reason was not
refreshing the records. I don't know why, and looked in ng's and in Help
for the differences between the 2, but it seemed me.requery was the one to
use, and yet it wasn't refreshing the records. Oddly, at times I also
needed to use the menu item Records-->remove filter/sort in order to refresh
the records as well. I gave up trying to figure out what the deal was with
that. I'll keep fiddling w/ me.requery, but I had very little luck with it.

- CustNum is indeed the related field in the production table to the
corresponding CustID in the Customer List. I was not being consistent w/
control naming, but the JRCustNum is the form's control name that the query
looks at in terms of criteria for the CustNum (aka CustID) field.

The way I wanted this to work is that:

A form has several unbound controls in the header that will all contain the
criteria that the underlying recordsource query uses to refresh the data as
each criteria is changed. The criteria that will continuously be modified
are:

- EnteredBy (a combobox that stores Employee ID, its row source is a query
that looks up Employee ID's that belong to Order Entry Department.). Query
criteria WAS:

[Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] OR
[Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] is null

However, after the requery wasn't working right because I seemed to have too
many fields using the "or is null" to allow for user not wanting to apply
criteria to that particular field, I am now using:

Like [Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] & "*"

- ProcessedBy (a combobox that stores Employee ID, its row source is a query
that looks up Employee ID's that belong to Order Processing Department).
Query criteria is:

Like [Forms]![ThisFormWe'reAllTalkingAbout]![ProcessedBy] & "*" (see above
criteria explanation)

- MadeBy (a combobox that stores Employee ID, its row source is a query that
looks up Employee ID's that belong to Order Production Department). Query
criteria is:

Like [Forms]![ThisFormWe'reAllTalkingAbout]![MadeBy] & "*"

- Customer (combobox storing Customer ID, row source is Customer List
table). Query criteria is:

[Forms]![ThisFormWe'reAllTalkingAbout]![CustNum] or
[Forms]![ThisFormWe'reAllTalkingAbout]![CustNum] is null

....the whole "Like [formcontrol] & *" was not working with this particular
control for some reason, so I reverted back to the "Or is null" technique.

- OrderEntryTurnaround (a calculated field in the query - it is
[DateEntered] - [DateReceived], and the criteria is:
=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderEntryTurnaround] OR
([DateEntered] is null) and
(Date()-[DateReceived]>=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderEntryTu
rnaround])

- OrderProcessTurnaround (a calculated field in the query - it is
[DateProcessed] - [DateEntered], and the criteria is:
=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderProcessTurnaround] OR
([DateProcessed] is null) and
(Date()-[DateEntered]>=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderProcessT
urnaround])

- OrderProductionTurnaround (a calculated field in the query - it is
[DateProduced] - [DateProcessed], and the criteria is:
=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderProducedTurnaround] OR
([DateProduced] is null) and
(Date()-[DateProcessed]>=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderProduc
edTurnaround])

- OrderTotalTurnaround (a calculated field in the query - it is
[DateProduced] - [DateReceived], and the criteria is:
=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderTotalTurnaround] OR
([DateProduced] is null) and
(Date()-[DateReceived]>=[Forms]![ThisFormWe'reAllTalkingAbout]![OrderTotalTu
rnaround])

- StartDate
- EndDate (these two set the date range to look for results, and in the
query criteria, DateReceived has:

Between [Forms]![ThisFormWe'reAllTalkingAbout]![StartDate] and
[Forms]![ThisFormWe'reAllTalkingAbout]![EndDate])


So, what I'm trying to do is requery whenever any of the above is changed by
the user. Combining all this, including the "or is nulls" seems to make a
query too complex, where the nulls are producing different results, the
records only change when the parameters are set in a certain order,
sometimes I have to choose records-->remove filter/sort to show the new data
after a parameter is set, etc.

Would it be possible to get a SQL string that accomplishes what is being
described above without erroring Access about a query that's too complex?

Thanks again for the time and assistance.









Dirk Goldgar said:
rgrantz said:
Thanks for the response. Below is the info requested:

SQL of recordsource (although I use the query builder):

SELECT ProductionData.EnteredBy, EmpList.EmpName,
ProductionData.DateRec, ProductionData.DateEntered,
ProductionData.ItemPartNum, ProductionData.PSNum,
ProductionData.CustNum, CustomerList.CustName, ProductionData.Status,
OrderStatusList.Status2, ProductionData.DateDes,
ProductionData.SqFoot, ProductionData.AutoDes, ProductionData.DesBy,
EmpList_1.EmpName, ProductionData.Notes, ItemData.ItemNum,
ItemData.DateProd, ItemData.Vendor, VendorList.VendorName,
ItemData.Wall, ItemData.Floor, ItemData.Bead, ItemData.MachineNum,
ItemData.ShiftProd, ItemData.OperatorNum, EmpList_2.EmpName,
ItemData.PartnerNum, EmpList_3.EmpName, ItemData.Verifier1Num,
EmpList_4.EmpName, ItemData.Verifier2Num, EmpList_5.EmpName,
ItemData.[2ndVerifier1Num], ItemData.[2ndVerifier2Num],
ItemData.TurnaroundDays, ItemData.Notes, [DateEntered]-[DateRec] AS
EntryTurn, [DateDes]-[DateEntered] AS DesignTurn,
[DateProd]-[DateDes] AS ProdTurn, [DateProd]-[DateEntered] AS
TotalTurn

FROM EmpList AS EmpList_4 RIGHT JOIN (EmpList AS EmpList_3 RIGHT JOIN
(CustomerList RIGHT JOIN (OrderStatusList RIGHT JOIN (VendorList
RIGHT JOIN (EmpList AS EmpList_5 RIGHT JOIN (EmpList AS EmpList_2
RIGHT JOIN (EmpList AS EmpList_1 RIGHT JOIN (EmpList RIGHT JOIN
(ItemData RIGHT JOIN ProductionData ON ItemData.PSNum =
ProductionData.PSNum) ON EmpList.EmpID = ProductionData.EnteredBy) ON
EmpList_1.EmpID = ProductionData.DesBy) ON EmpList_2.EmpID =
ItemData.OperatorNum) ON EmpList_5.EmpID = ItemData.Verifier2Num) ON
VendorList.VendorID = ItemData.Vendor) ON OrderStatusList.ID =
ProductionData.Status) ON CustomerList.CustID =
ProductionData.CustNum) ON EmpList_3.EmpID = ItemData.PartnerNum) ON
EmpList_4.EmpID = ItemData.Verifier1Num

WHERE (((ProductionData.EnteredBy) Like
[Forms]![frmMainReport]![JREnteredBy] & "*") AND
((ProductionData.CustNum)=[Forms]![frmMainReport]![JRCustNum]) AND
((ProductionData.DesBy) Like [Forms]![frmMainReport]![JRDesBy] & "*")
AND
(([DateEntered]-[DateRec])>=[Forms]![frmMainReport]![JREntryTurn])
AND (([DateDes]-[DateEntered])>=[Forms]![frmMainReport]![JRDesTurn])
AND (([DateProd]-[DateDes])>=[Forms]![frmMainReport]![JRProdTurn])
AND
(([DateProd]-[DateEntered])>=[Forms]![frmMainReport]![JRTotalTurn]))
OR ((([Forms]![frmMainReport]![JRCustNum]) Is Null));

As you may have guessed, the multiple EmpName and EmpList entries are
using one Employee List table to show names for employee numbers, or
to show specific department employees in the criteria drop-downs.
The "Like [formfield] & *" is to return all records in that field
even when no value is chosen (ie. no criteria applied).

Row Source of Customer Combobox:

SELECT [CustomerList].[CustID], [CustomerList].[CustName] FROM
CustomerList;

Column Count: 2
Bound Column: 1
AfterUpdate: Docmd.Requery (with the understood Sub/End Sub wrap in
the module window)


Since I posted that last problem, I've run into several more. It
seems my query's just getting too complex, as I have 7 unbound
controls with the AfterUpdates set to DoCmd.Requery, and the criteria
in the query pulling from these 7 separate unbound controls. I'm
getting extremely unpredictable results that simply are not adding
up. Is my placement of the Is Nulls and the Or Isnulls in the query
builder messed up? This form working correctly seems to depend on
the order in which I set the criteria in the form. You can see the
unbound controsl in the SQL, they are all the ones that express
criteria. I need to be able to allow for the calculated fields
having nulls (ie. DateProd. might be Null, so TotalTurn (turnaround
time from receipt of order to date produced) needs to be able to have
nulls.

Why isn't this working? Am I just trying to do to much on one form?
I can put this DB somewhere for download if people want to see the
weird behavior of this form.

I don't think we have any reason to believe that the query is too
complex. I do have a few questions and a suggestion. First, the
suggestion: where you have the VBA statement "Docmd.Requery", in you
AfterUpdate event procedures, change that to "Me.Requery". That is more
efficient, and eliminates any possibility that Access is getting
confused about exactly what needs to be requeried. If you have a
statement that requeries a specific control name with 'DoCmd.Requery
"<control name>"', change that to 'Me!<control name>.Requery'.

Questions:

1. You have repeatedly referred to the combo box in question as
"Customer". But the control reference in your query criterion is to
"[Forms]![frmMainReport]![JRCustNum]". Which is correct? If the combo
box is named "Customer", that's what your control reference should use.

2. I notice that the primary key field in table CustomerList is named
"CustID". Am I right in believing that in other tables, CustNum is the
name of the foreign key field that relates to CustID? It appears so
from the SQL, but I want to make sure.

3. You may well have your "OR Is Null" subclauses messed up. How do you
want to have this work? Do you want each of these criterion controls
ignored in the query's Where clause if the control is Null? If so, you
might try this (untested) revision of your WHERE clause:

WHERE
(ProductionData.EnteredBy Like
[Forms]![frmMainReport]![JREnteredBy] & "*")
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
AND
(ProductionData.DesBy Like
[Forms]![frmMainReport]![JRDesBy] & "*")
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
([Forms]![frmMainReport]![JREntryTurn] Is Null)
)
AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
([Forms]![frmMainReport]![JRDesTurn] Is Null)
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
([Forms]![frmMainReport]![JRProdTurn] Is Null)
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
([Forms]![frmMainReport]![JRTotalTurn] Is Null)
)


On the other hand, that may not be what you're after.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

[...]
- EnteredBy (a combobox that stores Employee ID, its row source is a
query that looks up Employee ID's that belong to Order Entry
Department.). Query criteria WAS:

[Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] OR
[Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] is null

However, after the requery wasn't working right because I seemed to
have too many fields using the "or is null" to allow for user not
wanting to apply criteria to that particular field, I am now using:

Like [Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] & "*"

I would not use this technique with numeric fields. At the least, you
may have a problem with getting back the record for employee 1234 when
you wanted employee 1.

[...]
So, what I'm trying to do is requery whenever any of the above is
changed by the user. Combining all this, including the "or is nulls"
seems to make a query too complex, where the nulls are producing
different results, the records only change when the parameters are
set in a certain order, sometimes I have to choose records-->remove
filter/sort to show the new data after a parameter is set, etc.

Would it be possible to get a SQL string that accomplishes what is
being described above without erroring Access about a query that's
too complex?

When you refer to the query being "too complex", are you getting an
error message that says the query is too complex, or are you just
concluding that's the problem because you aren't getting the results
back that you expect? Did you try the SQL revision that I posted? What
was the result? David pointed out that there have been some problems
with the proper refreshing of parameters, but before pursuing that as a
possibility, I want to be sure that you're working with a well-formed
SQL statement that really should return the records you want when it is
evaluated. I'm not convinced of that yet.
 
D

Dirk Goldgar

david epsom dot com dot au said:
dunno.

There is a KB article somewhere about cbo's not refreshing
correctly when the cbo uses a cached copy of the binary
copy of the query, rather than rebuilding the query from
the sql, after a parameter value has changed.

Steven Lebans posted something somewhere about using ListCount
to force a cbo to complete its data query (like using MoveLast
before RecordCount)

In A97 I had code like this:
Me!cbo1.RowSource = fnRowSourceSQL()
Me.cbo1.Requery
DoCmd.Requery Me.cbo1
Which noticeably failed to do anything useful. A dummy function
inside the query proved that the query never ran until the
cbo list was 'dropped down' - the problem was fixed by using
.ListCount instead of .ReQuery.

I'm familiar with using the ListCount property to get the scroll bar to
work correctly, but I haven't run into a case where it was needed to get
the query to run. Very interesting.
 
R

rgrantz

I retitled this for future searches, as the problem and solution seem to be
getting away from the original post title. OK, I've been trying to apply
query logic using the SQL text editor rather than the query grid, as it
seems Access adds a whole bunch of opening and closing parenthesis and the
like, which messes up the order of criteria checked, etc. All criteria are
provided via unbound controls on the form. I have the following as the
Where Clause (my own comments for this post are preceded by the typical '
comment statement in VBA), and Access returns a "query is too complex"
message:

WHERE
(
(ProductionData.EnteredBy =
[Forms]![frmMainReport]![JREnteredBy])
OR
([Forms]![frmMainReport]![JREnteredBy] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(ProductionData.DesBy =
[Forms]![frmMainReport]![JRDesBy])
OR
([Forms]![frmMainReport]![JRDesBy] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
(([DateEntered] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
)
' the above returns all records where the number of days between DateRec and
DateEntered is more than or equal to the number put in the JREntryTurn
field. ALSO, if for any record the DateEntered field has not been entered
yet, it will show records where the number of days between today's date and
DateRec is more than or equal to the JREntryTurn field value (I don't need
to check for null value with this). This is because turnaround for the
entry of orders received should still be shown for orders that are received
but haven't been entered yet. The same principal applies to the remaining
criteria below.
AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
(([DateDes] Is Null) and (Date()-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
(([DateProd] Is Null) and (Date()-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
(([DateProd] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JRTotalTurn])
)

Now, the query can't be opened in SQL view, but I DID notice that before I
added a couple additional criteria, Access did replace the original SQL that
I typed in myself with a HUGE increase in text after the query was run using
the form (ie. I typed in the SQL string seen above, saved and closed the
query, opened the form whose recordsource is this query, changed a fiew
criteria and refreshed, and then came back to the query and opened it in SQL
view, and saw that there was at least 5 times the amount of text and
parenthetical phrases as what I had originally typed). I don't know if
Access automatically changing the logic to longer strings is part of the
problem or not.

I can make this DB available for DL if someone wants to see this behaviour
duplicated.

Can anyone tell me a way to accomplish the SQL string above without a "too
complex" error?





Dirk Goldgar said:
[...]
- EnteredBy (a combobox that stores Employee ID, its row source is a
query that looks up Employee ID's that belong to Order Entry
Department.). Query criteria WAS:

[Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] OR
[Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] is null

However, after the requery wasn't working right because I seemed to
have too many fields using the "or is null" to allow for user not
wanting to apply criteria to that particular field, I am now using:

Like [Forms]![ThisFormWe'reAllTalkingAbout]![EnteredBy] & "*"

I would not use this technique with numeric fields. At the least, you
may have a problem with getting back the record for employee 1234 when
you wanted employee 1.

[...]
So, what I'm trying to do is requery whenever any of the above is
changed by the user. Combining all this, including the "or is nulls"
seems to make a query too complex, where the nulls are producing
different results, the records only change when the parameters are
set in a certain order, sometimes I have to choose records-->remove
filter/sort to show the new data after a parameter is set, etc.

Would it be possible to get a SQL string that accomplishes what is
being described above without erroring Access about a query that's
too complex?

When you refer to the query being "too complex", are you getting an
error message that says the query is too complex, or are you just
concluding that's the problem because you aren't getting the results
back that you expect? Did you try the SQL revision that I posted? What
was the result? David pointed out that there have been some problems
with the proper refreshing of parameters, but before pursuing that as a
possibility, I want to be sure that you're working with a well-formed
SQL statement that really should return the records you want when it is
evaluated. I'm not convinced of that yet.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

rgrantz said:
I retitled this for future searches, as the problem and solution seem
to be getting away from the original post title. OK, I've been
trying to apply query logic using the SQL text editor rather than the
query grid, as it seems Access adds a whole bunch of opening and
closing parenthesis and the like, which messes up the order of
criteria checked, etc. All criteria are provided via unbound
controls on the form. I have the following as the Where Clause (my
own comments for this post are preceded by the typical ' comment
statement in VBA), and Access returns a "query is too complex"
message:

WHERE
(
(ProductionData.EnteredBy =
[Forms]![frmMainReport]![JREnteredBy])
OR
([Forms]![frmMainReport]![JREnteredBy] Is Null)
)
' the above returns records matching control value or all records if
control is null
AND
(
(ProductionData.DesBy =
[Forms]![frmMainReport]![JRDesBy])
OR
([Forms]![frmMainReport]![JRDesBy] Is Null)
)
' the above returns records matching control value or all records if
control is null
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
' the above returns records matching control value or all records if
control is null
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
(([DateEntered] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
)
' the above returns all records where the number of days between
DateRec and DateEntered is more than or equal to the number put in
the JREntryTurn field. ALSO, if for any record the DateEntered field
has not been entered yet, it will show records where the number of
days between today's date and DateRec is more than or equal to the
JREntryTurn field value (I don't need to check for null value with
this). This is because turnaround for the entry of orders received
should still be shown for orders that are received but haven't been
entered yet. The same principal applies to the remaining criteria
below. AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
(([DateDes] Is Null) and (Date()-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
(([DateProd] Is Null) and (Date()-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
(([DateProd] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JRTotalTurn])
)

Now, the query can't be opened in SQL view, but I DID notice that
before I added a couple additional criteria, Access did replace the
original SQL that I typed in myself with a HUGE increase in text
after the query was run using the form (ie. I typed in the SQL string
seen above, saved and closed the query, opened the form whose
recordsource is this query, changed a fiew criteria and refreshed,
and then came back to the query and opened it in SQL view, and saw
that there was at least 5 times the amount of text and parenthetical
phrases as what I had originally typed). I don't know if Access
automatically changing the logic to longer strings is part of the
problem or not.

I can make this DB available for DL if someone wants to see this
behaviour duplicated.

Can anyone tell me a way to accomplish the SQL string above without a
"too complex" error?

I take it that the comments in your SQL aren't actually present in the
SQL -- naturally, that wouldn't work. Aside from that, which seems
unlikely, I don't see offhand what's wrong with your SQL statement.
Although Access does have a tendency to rewrite your SQL to make it
easier to display in the query designer, that doesn't normally cause
good SQL to fail.

I'd be interested in having a look at your database, if you can make it
small enough not to be burden on my poor dial-up internet connection.
If you'd like to send me a cut-down copy of the database, containing
*only* the elements necessary to demonstrate the problem, compacted and
then zipped to less than 1MB in size (preferably much smaller) -- I'll
have a look at it, time permitting. You can send it to the address
derived by removing NO SPAM from the reply address of this message.
 

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