A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"You canceled the previous operation."



 
 
Thread Tools Display Modes
  #11  
Old August 29th, 2005, 01:34 AM
John Spencer (MVP)
external usenet poster
 
Posts: n/a
Default

HOOORAY!!!

Sorry about the typo. I do that. Part of the reason is that I avoid object
names with spaces and special characters. That way I can get away with not
using the [] around items.

"Steven L via AccessMonster.com" wrote:

SCRATH THAT! Works now!

I didn't spot the typo in your first solution, hence the pop-up boxes. Thanks
you so much. You've saved my life.

Steve

Steven L wrote:
Hi John,

You hit it right on the head with the zero length string and null value point.
I remembered the table of error values created when I imported this table
from excel. I looked up any errors in the motcode field, and sure enough,
there were 76 of them, the exact same number of records missing from my
search results.

I tried the code you wrote the previous time, and it looks like it should
work, but everytime I run the query I get pop-up boxes (twice) asking for the
value of [Forms]![Case-BasedQuery]![motcode]. Can you really join two sets of
values with OR? I ask because I tried to set the criteria to accept either
the values 1 or 2, like so:
IIf([Forms]![Case-Based Query]![motcode] Is Not Null,[Forms]![Case-Based
Query]![motcode],1 or 2)
... but it just returned no results. Tried '1 & 2' but that just gives me
results where motcode=12.

I've just now tried to use Nz as well, but am not having much luck there
either. Using the fragment of code you gave yields the same number of results,
and I think I can see that's because Nz never evaluates [combined simple].
motcode as null because [combined simple].motcode contains all possible
values of motcode. Does that make sense?

Even if Nz evaluates to null I don't think it'd help me in this case as all I
could do is set it to another value, say -999, that doesn't exist in the
table. Therefore, I'd still not get the missing results as it'd still be
ignoring the null values in the table.

I'm thinking maybe I should run a sub that replaces all the null values in
the table with some dummy value. Would rather find some other way though as
it just complicates things and also leaves a bunch of ugly '-999's everywhere

Thanks again for helping. Really appreciate it.

Steve

Whoops! Change the last line of the first paragraph to read

[quoted text clipped - 6 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200508/1

  #12  
Old August 29th, 2005, 09:25 PM
Steven L via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Hmm, not out of the woods yet it seems. Using the code fragement you wrote
works beautifully on all fields with comboboxes, but I'm now having trouble
with the five checkboxes remaining. Unlike the comboboxes where I could just
accept the values currently in the combobox, for the checkboxes I need to set
the value equal to '1' if it's checked. So I've been using IIf functions,
which is currently giving me "too complicated to evaluate" grief.

Just for reference, the query now looks like this:
================================================== ================
SELECT [combined simple].org_case_no, [combined simple].ccr, [combined simple]
..c_year, [combined simple].c_18district, [combined simple].motcode, [combined
simple].vsex, [combined simple].vage, [combined simple].offsexcode, [combined
simple].offage, [combined simple].relacode, [combined simple].viet_camp,
[combined simple].c_rob_bur_c, [combined simple].vic_nonc, [combined simple].
offchi, [combined simple].sex_as_c, [combined simple].weafirea, [combined
simple].ID
FROM [combined simple]
WHERE (
(([combined simple].c_year)=
[Forms]![Case-Based Query]![c_year] Or [Forms]![Case-Based Query]![c_year] Is
Null)
AND
(([combined simple].c_18district)=
[Forms]![Case-Based Query]![c_18district] Or [Forms]![Case-Based Query]!
[c_18district] Is Null)
AND
(([combined simple].org_case_no)=
[Forms]![Case-Based Query]![org_case_no] Or [Forms]![Case-Based Query]!
[org_case_no] Is Null)
AND
(([combined simple].ccr)=[Forms]![Case-Based Query]![ccr] Or [Forms]![Case-
Based Query]![ccr] Is Null) AND
(([combined simple].motcode)=
[Forms]![Case-Based Query]![motcode] Or [Forms]![Case-Based Query]![motcode]
Is Null)
AND
(([combined simple].vsex)=
[Forms]![Case-Based Query]![vsex] Or [Forms]![Case-Based Query]![vsex] Is
Null)
AND
(([combined simple].vage)=
[Forms]![Case-Based Query]![vage] Or [Forms]![Case-Based Query]![vage] Is
Null)
AND
(([combined simple].offsexcode)=
[Forms]![Case-Based Query]![offsexcode] Or [Forms]![Case-Based Query]!
[offsexcode] Is Null)
AND
(([combined simple].offage)=
[Forms]![Case-Based Query]![offage] Or [Forms]![Case-Based Query]![offage] Is
Null)
AND
(([combined simple].relacode)=
[Forms]![Case-Based Query]![relacode] Or [Forms]![Case-Based Query]![relacode]
Is Null)
AND
(([combined simple].weafirea)=
[Forms]![Case-Based Query]![weafirea] Or [Forms]![Case-Based Query]![weafirea]
Is Null)
);
================================================== =============


Now I'm trying to add another criteria in there for the checkboxes. I figure
I have to use the IIf function to tell the query to set [combined simple].
viet_camp to '1' (values for viet_camp are stored as text) if [Forms]![Case-
Based Query]![viet_camp] is -1. So far it works fine when the box is checked,
i.e. assigning the value '1' works. However, when I don't check the box I
can't seem to bring up the records with empty strings for viet_camp. So far
I've tried:

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[combined simple].viet_camp]
)
---- Gives results where viet_camp equals 0 or 1, but not zero string values
(viet_camp can have values of "0", "1" and "").

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[Forms]![Case-Based Query]!
[viet_camp])
---- Gives results where viet_camp=0. [Forms]![Case-Based Query]![viet_camp]
will, of course, only give values -1 and 0, so I can see why only the 0
results are coming up.

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[Forms]![Case-Based Query]!
[viet_camp] Or [Forms]![Case-Based Query]![viet_camp] Is Null)
---- "Too complex to be evaluated"

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[Forms]![Case-Based Query]!
[viet_camp] Is Null)
---- Again, "too complex to be evaluated"

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',Null)
---- Returned no records whatsoever.

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[combined simple].viet_camp
Or [combined simple].viet_camp] Is Null)
---- "too complicated to be evaluated"

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[combined simple].viet_camp
Or "")
---- "too complicated to be evaluated"

Any way I can force the query to include the records where viet_camp is an
empty string?

Thanks again for all the help.

Steve


P.S. The typo's really my fault for using names with spaces in them. This is
my first Access project and I find myself putting spaces in names simply
because I can. Ugly habit, I know.

P.P.S. This query is killing my comp's memory. I now can only edit it through
sql view as apparently there's not enough memory to view it in design view.
Doesn't particularly bother me though, I prefer the sql view, but I hope it
doesn't bring the whole database crashing down some day...





John Spencer (MVP) wrote:
HOOORAY!!!

Sorry about the typo. I do that. Part of the reason is that I avoid object
names with spaces and special characters. That way I can get away with not
using the [] around items.

SCRATH THAT! Works now!

[quoted text clipped - 45 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...



--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200508/1
  #13  
Old August 29th, 2005, 11:52 PM
John Spencer (MVP)
external usenet poster
 
Posts: n/a
Default

The problem is you have too many criteria to use the technique. Everytime you
add another criterion, Access will redo the query criteria (internally) and add
many more lines. Eventually it gets too complex for Access/Jet to handle.

If you need to evaluate 5 checkboxes and 11 comboboxes, the code is going to be
too complex. It looks as if you may have to build the query using VBA.

As far as turning the checkbox into 1 from -1, I would simply use the abs function.

Abs([Forms]![Case-Based Query]![viet_camp])
will return 1 or 0 assuming that viet_camp is a two-state checkbox.

As I said, you will probably have to go to building the query statement using
VBA. How are you using the query results? As a source for a report or a form?
Or in some other manner? And how familar are you with using VBA?


"Steven L via AccessMonster.com" wrote:

Hmm, not out of the woods yet it seems. Using the code fragement you wrote
works beautifully on all fields with comboboxes, but I'm now having trouble
with the five checkboxes remaining. Unlike the comboboxes where I could just
accept the values currently in the combobox, for the checkboxes I need to set
the value equal to '1' if it's checked. So I've been using IIf functions,
which is currently giving me "too complicated to evaluate" grief.

Just for reference, the query now looks like this:
================================================== ================
SELECT [combined simple].org_case_no, [combined simple].ccr, [combined simple]
.c_year, [combined simple].c_18district, [combined simple].motcode, [combined
simple].vsex, [combined simple].vage, [combined simple].offsexcode, [combined
simple].offage, [combined simple].relacode, [combined simple].viet_camp,
[combined simple].c_rob_bur_c, [combined simple].vic_nonc, [combined simple].
offchi, [combined simple].sex_as_c, [combined simple].weafirea, [combined
simple].ID
FROM [combined simple]
WHERE (
(([combined simple].c_year)=
[Forms]![Case-Based Query]![c_year] Or [Forms]![Case-Based Query]![c_year] Is
Null)
AND
(([combined simple].c_18district)=
[Forms]![Case-Based Query]![c_18district] Or [Forms]![Case-Based Query]!
[c_18district] Is Null)
AND
(([combined simple].org_case_no)=
[Forms]![Case-Based Query]![org_case_no] Or [Forms]![Case-Based Query]!
[org_case_no] Is Null)
AND
(([combined simple].ccr)=[Forms]![Case-Based Query]![ccr] Or [Forms]![Case-
Based Query]![ccr] Is Null) AND
(([combined simple].motcode)=
[Forms]![Case-Based Query]![motcode] Or [Forms]![Case-Based Query]![motcode]
Is Null)
AND
(([combined simple].vsex)=
[Forms]![Case-Based Query]![vsex] Or [Forms]![Case-Based Query]![vsex] Is
Null)
AND
(([combined simple].vage)=
[Forms]![Case-Based Query]![vage] Or [Forms]![Case-Based Query]![vage] Is
Null)
AND
(([combined simple].offsexcode)=
[Forms]![Case-Based Query]![offsexcode] Or [Forms]![Case-Based Query]!
[offsexcode] Is Null)
AND
(([combined simple].offage)=
[Forms]![Case-Based Query]![offage] Or [Forms]![Case-Based Query]![offage] Is
Null)
AND
(([combined simple].relacode)=
[Forms]![Case-Based Query]![relacode] Or [Forms]![Case-Based Query]![relacode]
Is Null)
AND
(([combined simple].weafirea)=
[Forms]![Case-Based Query]![weafirea] Or [Forms]![Case-Based Query]![weafirea]
Is Null)
);
================================================== =============

Now I'm trying to add another criteria in there for the checkboxes. I figure
I have to use the IIf function to tell the query to set [combined simple].
viet_camp to '1' (values for viet_camp are stored as text) if [Forms]![Case-
Based Query]![viet_camp] is -1. So far it works fine when the box is checked,
i.e. assigning the value '1' works. However, when I don't check the box I
can't seem to bring up the records with empty strings for viet_camp. So far
I've tried:

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[combined simple].viet_camp]
)
---- Gives results where viet_camp equals 0 or 1, but not zero string values
(viet_camp can have values of "0", "1" and "").

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[Forms]![Case-Based Query]!
[viet_camp])
---- Gives results where viet_camp=0. [Forms]![Case-Based Query]![viet_camp]
will, of course, only give values -1 and 0, so I can see why only the 0
results are coming up.

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[Forms]![Case-Based Query]!
[viet_camp] Or [Forms]![Case-Based Query]![viet_camp] Is Null)
---- "Too complex to be evaluated"

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[Forms]![Case-Based Query]!
[viet_camp] Is Null)
---- Again, "too complex to be evaluated"

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',Null)
---- Returned no records whatsoever.

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[combined simple].viet_camp
Or [combined simple].viet_camp] Is Null)
---- "too complicated to be evaluated"

[combined simple].viet_camp=
IIf([Forms]![Case-Based Query]![viet_camp]=-1,'1',[combined simple].viet_camp
Or "")
---- "too complicated to be evaluated"

Any way I can force the query to include the records where viet_camp is an
empty string?

Thanks again for all the help.

Steve

P.S. The typo's really my fault for using names with spaces in them. This is
my first Access project and I find myself putting spaces in names simply
because I can. Ugly habit, I know.

P.P.S. This query is killing my comp's memory. I now can only edit it through
sql view as apparently there's not enough memory to view it in design view.
Doesn't particularly bother me though, I prefer the sql view, but I hope it
doesn't bring the whole database crashing down some day...

John Spencer (MVP) wrote:
HOOORAY!!!

Sorry about the typo. I do that. Part of the reason is that I avoid object
names with spaces and special characters. That way I can get away with not
using the [] around items.

SCRATH THAT! Works now!

[quoted text clipped - 45 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200508/1

  #14  
Old August 30th, 2005, 08:09 PM
Steven L via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Yeah I noticed the design view racking up lots of extra lines that I hadn't
put in.
I'm using the query as the source for a subform. I'm new to VBA, but think
I'm fairly familiar with it now. I'm fine with loops, subs, functions,
modules and doing stuff like opening records and navigating/adding/deleting
from them.

I've never run a query from vba though. I think I saw an example once though
where the user wrote a string to represent the SQL and then ran a command to
run it. Is that the way you were suggesting I do it? Seems a little fiddly. I
currently can't see the design view, but can see the SQL view and the results,
so I'm quite happy to continue on that way, unless there's a reason that
won't work. Is there?

As far as the checkbox is concerned, I want the database to find records
where vietcamp=1 when the checkbox is checked, but take any values (0, 1 and
null) if it's not checked. Can't seem to force the query to accept the null
value though.

Steve

John Spencer (MVP) wrote:
The problem is you have too many criteria to use the technique. Everytime you
add another criterion, Access will redo the query criteria (internally) and add
many more lines. Eventually it gets too complex for Access/Jet to handle.

If you need to evaluate 5 checkboxes and 11 comboboxes, the code is going to be
too complex. It looks as if you may have to build the query using VBA.

As far as turning the checkbox into 1 from -1, I would simply use the abs function.

Abs([Forms]![Case-Based Query]![viet_camp])
will return 1 or 0 assuming that viet_camp is a two-state checkbox.

As I said, you will probably have to go to building the query statement using
VBA. How are you using the query results? As a source for a report or a form?
Or in some other manner? And how familar are you with using VBA?

Hmm, not out of the woods yet it seems. Using the code fragement you wrote
works beautifully on all fields with comboboxes, but I'm now having trouble

[quoted text clipped - 130 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...



--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200508/1
  #15  
Old August 31st, 2005, 02:46 AM
John Spencer (MVP)
external usenet poster
 
Posts: n/a
Default

What kind of field is VietCamp? Number field?

You can build the SQL string in VBA and then assign the string (if it is not TOO
long) as the record source of the form (subForm). An alternative is to have a
named query as the record source and edit its SQL.

Rough (Very Rough) Code

Dim StrSQL as String
Dim strWhere as String

strSQL = "SELECT org_case_no, ccr, c_year, c_18district, motcode," & _
"vsex, vage, offsexcode, offage, relacode, viet_camp," & _
"c_rob_bur_c, vic_nonc, offchi, sex_as_c, weafirea, ID " & _
" FROM [combined simple] AS CS"

If IsNull([Forms]![Case-Based Query]![c_year]) = False then
StrWHERE = StrWhere & " AND c_Year= " & [Forms]![Case-Based Query]![c_year]
End If

'Assumes c_18District is a string
If IsNull([Forms]![Case-Based Query]![c_18district]) = False then
StrWhere= StrWhere &" AND c_18district)=" & _
Chr(34) & [Forms]![Case-Based Query]![c_18district] & Chr(34)
End if
...

IF Forms]![Case-Based Query]![viet_camp] = -1 Then
StrWhere = StrWhere & " AND viet_camp = 1"
End If

....

StrWhere = Mid(strWhere, 6) ' Trim off the first " AND "
StrSQL = StrSQL & " WHERE " & StrWhere

'Now Assign that string to the record source of your form/subform object.


"Steven L via AccessMonster.com" wrote:

Yeah I noticed the design view racking up lots of extra lines that I hadn't
put in.
I'm using the query as the source for a subform. I'm new to VBA, but think
I'm fairly familiar with it now. I'm fine with loops, subs, functions,
modules and doing stuff like opening records and navigating/adding/deleting
from them.

I've never run a query from vba though. I think I saw an example once though
where the user wrote a string to represent the SQL and then ran a command to
run it. Is that the way you were suggesting I do it? Seems a little fiddly. I
currently can't see the design view, but can see the SQL view and the results,
so I'm quite happy to continue on that way, unless there's a reason that
won't work. Is there?

As far as the checkbox is concerned, I want the database to find records
where vietcamp=1 when the checkbox is checked, but take any values (0, 1 and
null) if it's not checked. Can't seem to force the query to accept the null
value though.

Steve

John Spencer (MVP) wrote:
The problem is you have too many criteria to use the technique. Everytime you
add another criterion, Access will redo the query criteria (internally) and add
many more lines. Eventually it gets too complex for Access/Jet to handle.

If you need to evaluate 5 checkboxes and 11 comboboxes, the code is going to be
too complex. It looks as if you may have to build the query using VBA.

As far as turning the checkbox into 1 from -1, I would simply use the abs function.

Abs([Forms]![Case-Based Query]![viet_camp])
will return 1 or 0 assuming that viet_camp is a two-state checkbox.

As I said, you will probably have to go to building the query statement using
VBA. How are you using the query results? As a source for a report or a form?
Or in some other manner? And how familar are you with using VBA?

Hmm, not out of the woods yet it seems. Using the code fragement you wrote
works beautifully on all fields with comboboxes, but I'm now having trouble

[quoted text clipped - 130 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200508/1

  #16  
Old September 1st, 2005, 03:42 AM
Steven L via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Vietcamp is a number field.

"An alternative is to have a named query as the record source and edit its
SQL."
Yeah, this is what I'm doing at the moment, but I'm unable to get the query
to accept null values for vietcamp. Does running the sql query through vba
offer any advantages? I'm thinking that maybe I could run several queries in
vba (and use vba to check if vietcamp is checked) to get several sets of
reults and then join them up later on, perhaps like so:

query1:
select * from [combined simple]
where [combined simple].ccr=[Forms]![Case-Based Query]![ccr] Or [Forms]![Case-
Based Query]![ccr] Is Null
and [combined simple].org_case_no=[Forms]![Case-Based Query]![org_case_no] Or
[Forms]![Case-Based Query]![org_case_no] Is Null
and ...
....
....
.... and [combined simple].motcode=[Forms]![Case-Based Query]![motcode] Or
[Forms]![Case-Based Query]![motcode] Is Null

vba to check vietcamp: (call it query2)
If vietcamp=-1 Then
// write code to run this query: select * from [combined simple] where
vietcamp=1
Else
// write code to run query that will accept all values of vietcamp
End If

query3: (join them up)
select * from query1,query2
where query1.ID=query2.ID

I haven't tried it yet, but I think it will work. But I'm not sure how to go
about executing the third query. If I store the results of the first two
queries in recordsets, how will I refer to them in the third query? Is there
a way? I suppose I could create a bunch of real tables with nothing in them,
repopulate them each time the query is run and then do query three, but it
seems a little messy and would create more tables than I'd prefer. What do
you think would be the best way to go about this?

I also worry that it might be slow, what with all the extra queries and
joining. Also, if the entire query is executed through vba in the form, then
presumably other forms will have no way of accessing the query, which isn't a
problem right now, but could be later on if I design another form that uses
the same query. Unless, again, I store the results in a table after finishing
the query

Steve

John Spencer (MVP) wrote:
What kind of field is VietCamp? Number field?

You can build the SQL string in VBA and then assign the string (if it is not TOO
long) as the record source of the form (subForm). An alternative is to have a
named query as the record source and edit its SQL.

Rough (Very Rough) Code

Dim StrSQL as String
Dim strWhere as String

strSQL = "SELECT org_case_no, ccr, c_year, c_18district, motcode," & _
"vsex, vage, offsexcode, offage, relacode, viet_camp," & _
"c_rob_bur_c, vic_nonc, offchi, sex_as_c, weafirea, ID " & _
" FROM [combined simple] AS CS"

If IsNull([Forms]![Case-Based Query]![c_year]) = False then
StrWHERE = StrWhere & " AND c_Year= " & [Forms]![Case-Based Query]![c_year]
End If

'Assumes c_18District is a string
If IsNull([Forms]![Case-Based Query]![c_18district]) = False then
StrWhere= StrWhere &" AND c_18district)=" & _
Chr(34) & [Forms]![Case-Based Query]![c_18district] & Chr(34)
End if
...

IF Forms]![Case-Based Query]![viet_camp] = -1 Then
StrWhere = StrWhere & " AND viet_camp = 1"
End If

...

StrWhere = Mid(strWhere, 6) ' Trim off the first " AND "
StrSQL = StrSQL & " WHERE " & StrWhere

'Now Assign that string to the record source of your form/subform object.

Yeah I noticed the design view racking up lots of extra lines that I hadn't
put in.

[quoted text clipped - 38 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...



--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200509/1
  #17  
Old September 1st, 2005, 03:46 AM
Steven L via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Actually ignore all that stuff I wrote for now as I haven't tried your code
yet. I'll report back here when if it succeeds or not. Thanks.

Steve

Steven L wrote:
Vietcamp is a number field.

"An alternative is to have a named query as the record source and edit its
SQL."
Yeah, this is what I'm doing at the moment, but I'm unable to get the query
to accept null values for vietcamp. Does running the sql query through vba
offer any advantages? I'm thinking that maybe I could run several queries in
vba (and use vba to check if vietcamp is checked) to get several sets of
reults and then join them up later on, perhaps like so:

query1:
select * from [combined simple]
where [combined simple].ccr=[Forms]![Case-Based Query]![ccr] Or [Forms]![Case-
Based Query]![ccr] Is Null
and [combined simple].org_case_no=[Forms]![Case-Based Query]![org_case_no] Or
[Forms]![Case-Based Query]![org_case_no] Is Null
and ...
...
...
... and [combined simple].motcode=[Forms]![Case-Based Query]![motcode] Or
[Forms]![Case-Based Query]![motcode] Is Null

vba to check vietcamp: (call it query2)
If vietcamp=-1 Then
// write code to run this query: select * from [combined simple] where
vietcamp=1
Else
// write code to run query that will accept all values of vietcamp
End If

query3: (join them up)
select * from query1,query2
where query1.ID=query2.ID

I haven't tried it yet, but I think it will work. But I'm not sure how to go
about executing the third query. If I store the results of the first two
queries in recordsets, how will I refer to them in the third query? Is there
a way? I suppose I could create a bunch of real tables with nothing in them,
repopulate them each time the query is run and then do query three, but it
seems a little messy and would create more tables than I'd prefer. What do
you think would be the best way to go about this?

I also worry that it might be slow, what with all the extra queries and
joining. Also, if the entire query is executed through vba in the form, then
presumably other forms will have no way of accessing the query, which isn't a
problem right now, but could be later on if I design another form that uses
the same query. Unless, again, I store the results in a table after finishing
the query

Steve

What kind of field is VietCamp? Number field?

[quoted text clipped - 39 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...



--
Message posted via http://www.accessmonster.com
  #18  
Old September 1st, 2005, 01:26 PM
Steven L via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Worked like a charm! Thanks, you're a legend!

Steve

Steven L wrote:
Actually ignore all that stuff I wrote for now as I haven't tried your code
yet. I'll report back here when if it succeeds or not. Thanks.

Steve

Vietcamp is a number field.

[quoted text clipped - 52 lines]
WHERE (MotCode = [Forms]![Case-Based Query]![motcode] OR
[Forms]![Case-BasedQuery]![motcode] is Null) ...



--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200509/1
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
You canceled the previous operation Neil via AccessMonster.com General Discussion 2 August 15th, 2005 11:29 AM
"Operation has been canceled due to restrictions..." message Laura General Discussion 4 July 6th, 2005 07:59 PM
Outlook Error receiving mail ryan morano General Discussion 5 June 29th, 2005 07:16 PM
I'm getting e-mails stuck in the outbox, even after reinstall Age General Discussion 4 June 5th, 2005 01:16 AM
Corrupt Windows Componenet, or Outlook Problem? BPC23 com> General Discussion 0 May 27th, 2005 06:08 PM


All times are GMT +1. The time now is 05:47 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.