Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert count from 2 queries

Status
Not open for further replies.

extreme00

Technical User
Mar 25, 2008
4
0
0
US
I'm a MS Access programming newbie, can anyone please help me on the following?
Query1 contains the following :
varX
----
D

Query2 contains the following :
VarY
----
1
2
3

I'm trying to insert the count of these 2 queries into a new table, say TBLCount, so that TBLCount look like this :
CurrDate Count1 Count2
3/25/2008 1 3

I'm really at a loss at what to do now. I've tried joining tables which can't work, as these 2 queries has nothing in common. I've tried inserting 1 count, then updating the next count, but keep getting the updateable error.

Please help
 
INSERT INTO TBLCOUNT (CurrDate,Count1,Count2)
VALUES(DATE(),(SELECT COUNT(*) FROM Query1),(SELECT COUNT(*) FROM Query2))
 
Greetings extreme00,

Can you change Query1 to count the field VarX and change Query2 to count the field VarY (by hitting the Totals button in the Design View of the Query Builder, change "Group By" to "Count") add a field to both queries called something like "currdate" like this
currdate: format(now(),"mm/dd/yyyy")


Then create a third query as either an Append or Make Table Query use Query1 and Query2 as the source and use the currdate field as the Key.

Hope this helps,
Hovercraft
 
or you could do it all in one tidy package as eerlee's code shows.

...beat me by ~20 seconds.
 
Thanks so much for replying, eerlee!
However, I had to change the syntax due to the syntax error that MS Access prompted when saving.

This is what I've changed it to
INSERT INTO TBLCOUNT ([CurrDate],Count1,Count2)
VALUES(DATE(),(SELECT COUNT(*) FROM [Query1]),(SELECT COUNT(*) FROM [Query2]))
However, after running, this is the error message :
"Reserved Error (-3025), there is no message for this error"

A search on the net for this error code, yields no results. Any ideas?
 
Thanks to eerlee and Hovercraft and those who tried to help even if you have not posted the solutions yet.

I've mangaged to use DCount with success!!
These is how I've coded it :
INSERT INTO TBLCOUNT ( [CurrDate], Count1, Count2 )
VALUES (DATE(), DCount("[VarX]","[Query1]"), DCount("[VarY]","[Query2]"));

:D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top