Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Querying Access through Excel

Hi,

I have a spreadsheet that exports data into Access.
I used ADO/DAO to do this without a problem.

I am adding more functionality to the spreadsheet and want to be able
to tell if i am going to add duplicate records before they get added.
I want Excel to look at two columns in Access - "Year" and "Month" and
if they are the same as the year and month of the data that I am about
to enter I want a message to pop-up warning me that I could be
entering duplicate information.

I've tries the following:

sSQL = "SELECT * FROM Activity WHERE ([ReportingMonth]=1 AND
ReportingYear]=2004/2005)"
rs.Open sSQL, cn


MsgBox rs.RecordCount

If rs.RecordCount 0 Then MsgBox "duplication possible"

but the problem i come across is that rs.RecordCount displays "-1"
even when i have thousands of records that match the criteria.

Can anyone point out where i am going wrong.

many thanks in advance
chris dunigan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Querying Access through Excel

Without seeing your code, I'll make an educated guess. Move to the end of
the recordset before checking the record count. You may want to move back to
the beginning if you are going to do anything with the recordset besides
checking the count.

rs.MoveLast
rs.RecordCount

Troy

"Chris Dunigan" wrote in message
om...
Hi,

I have a spreadsheet that exports data into Access.
I used ADO/DAO to do this without a problem.

I am adding more functionality to the spreadsheet and want to be able
to tell if i am going to add duplicate records before they get added.
I want Excel to look at two columns in Access - "Year" and "Month" and
if they are the same as the year and month of the data that I am about
to enter I want a message to pop-up warning me that I could be
entering duplicate information.

I've tries the following:

sSQL = "SELECT * FROM Activity WHERE ([ReportingMonth]=1 AND
ReportingYear]=2004/2005)"
rs.Open sSQL, cn


MsgBox rs.RecordCount

If rs.RecordCount 0 Then MsgBox "duplication possible"

but the problem i come across is that rs.RecordCount displays "-1"
even when i have thousands of records that match the criteria.

Can anyone point out where i am going wrong.

many thanks in advance
chris dunigan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Querying Access through Excel

From the help file:

ADO 2.7 API Reference: RecordCount property: 'The property returns -1
when ADO cannot determine the number of records or if the provider or
cursor type does not support RecordCount.'

I'll guess you are using a forward only cursor and therefore
RecordCount is not supported.

Aside: you may need to take a look at the SQL, specifically how

ReportingYear=2004/2005

will be interpreted. Another guess, but if this is a 'text' column you
may need

ReportingYear='2004/2005'

If you want more than just guesses, I suggest you post your code,
schema and test data.

--

(Chris Dunigan) wrote in message . com...
Hi,

I have a spreadsheet that exports data into Access.
I used ADO/DAO to do this without a problem.

I am adding more functionality to the spreadsheet and want to be able
to tell if i am going to add duplicate records before they get added.
I want Excel to look at two columns in Access - "Year" and "Month" and
if they are the same as the year and month of the data that I am about
to enter I want a message to pop-up warning me that I could be
entering duplicate information.

I've tries the following:

sSQL = "SELECT * FROM Activity WHERE ([ReportingMonth]=1 AND
ReportingYear]=2004/2005)"
rs.Open sSQL, cn


MsgBox rs.RecordCount

If rs.RecordCount 0 Then MsgBox "duplication possible"

but the problem i come across is that rs.RecordCount displays "-1"
even when i have thousands of records that match the criteria.

Can anyone point out where i am going wrong.

many thanks in advance
chris dunigan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in querying data from MS Access aemAndy Excel Discussion (Misc queries) 1 April 16th 07 06:54 PM
QUERYING ACCESS Drew Excel Discussion (Misc queries) 3 July 13th 05 07:25 AM
Querying data from Access Steve J Excel Worksheet Functions 0 June 14th 05 10:16 AM
Querying Data from Access Stefan Excel Discussion (Misc queries) 2 June 2nd 05 07:10 PM
Querying Access Database Edgar Thoemmes Excel Worksheet Functions 1 December 15th 04 01:58 PM


All times are GMT +1. The time now is 03:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"