DB functions with MS Access 2003

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fuzzbug
Newbie
Posts: 5
Joined: Tue Oct 23, 2007 7:34 pm
Location: Watford, UK
Contact:

DB functions with MS Access 2003

Post by fuzzbug » Sun Jan 25, 2009 2:25 pm

I am trying to use the DB functions with MS Access 2003

I have a table called countries in a database called test

The table contains 2 records and 2 fields

The following script runs without errors but insists that the table contains zero records and zero fields. Why?


DBConnect>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb;User Id=admin;Password=;,dbEU3
DBQuery>dbEU3,select * from countries,tableCountries,NumRecs,NumFields,0
Message>records %NumRecs%
Message>records %NumFields%
FB

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Jan 25, 2009 9:39 pm

Is your connection string correct? What does DBConnect return? Should the user ID really be admin, but the password blank? Feel free to send your .mdb to support so that we can try it ourselves.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fuzzbug
Newbie
Posts: 5
Joined: Tue Oct 23, 2007 7:34 pm
Location: Watford, UK
Contact:

still trying to get DB functions to work

Post by fuzzbug » Tue Feb 03, 2009 12:12 pm

I decided going straight to Access was a bridge to far.

But, weirdly, I have the same problem with Excel as I do with Access.

I have an excel table called excel_Table.xls
Sheet1 contains:
tag name
ENG England
FRA France
(in cells A1 to B3)

The macro below runs without errors but is adamant that Sheet1 contains zero records and zero fields!

Code: Select all

Let>connStr=Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=%SCRIPT_DIR%\Macro_Testing\excel_Table.xls;DefaultDir=%SCRIPT_DIR%\Macro_Testing
DBConnect>connStr,dbCountries
Let>SQL=select * from [Sheet1$]
DBQuery>dbCountries,SQL,tableCountries,numRecs,numFields,0

Message>numRecs
Wait>0.5
Message>numFields
Wait>0.5
PS I also tried using:
Let>SQL=select * from [Sheet1$A1:B3]

but still no joy
FB

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 03, 2009 12:23 pm

As per my last response, feel free to send me your .xls file and I'll see if I get the same problem. Could be due to the data format. Or, since you're getting the same issue as you did with Access, perhaps there's a problem with your ADO/ODBC/MSOffice/Windows installation.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fuzzbug
Newbie
Posts: 5
Joined: Tue Oct 23, 2007 7:34 pm
Location: Watford, UK
Contact:

db functions difficult to debug!

Post by fuzzbug » Mon Feb 23, 2009 10:57 pm

Code: Select all

Let>connStr=Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=%SCRIPT_DIR%\excel_Table.xls;DefaultDir=%SCRIPT_DIR%
DBConnect>connStr,dbCountries
Let>SQL=select * from [countries!A2:B3]
DBQuery>dbCountries,SQL,tableCountries,numRecs,numFields
The above code returns numRecs=0 and numFields=0

excel_Table.xls contains one worksheet called countries

countries contains 6 active cells - A1 to B3:
tag name
ENG England
FRA France
FB

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 24, 2009 1:41 am

Try replacing this:

Let>SQL=select * from [countries!A2:B3]

With this:

Let>SQL=select * from [countries$]

While Microsofts docs say unnamed ranges can be used I have not been able to make it work. Instead retrieve the whole sheet and simply ignore the data you don't want.
Last edited by Marcus Tettmar on Tue Mar 17, 2009 3:16 pm, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fuzzbug
Newbie
Posts: 5
Joined: Tue Oct 23, 2007 7:34 pm
Location: Watford, UK
Contact:

still trying to get DB functions to work

Post by fuzzbug » Mon Mar 16, 2009 10:48 pm

no that did not work so I named the range and used the range like this:
Let>SQL=select * from [countries!country_names]

but the still the same: the script runs without errors but confidently reports that there are zero rows and zero columns

I have to say I am getting despondant.

Code: Select all

Let>connStr=Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=%SCRIPT_DIR%\excel_Table.xls;DefaultDir=%SCRIPT_DIR%
DBConnect>connStr,dbCountries
Let>SQL=select * from [countries!country_names]
DBQuery>dbCountries,SQL,tableCountries,numRecs,numFields

Message>numRecs
Wait>1
Message>numFields
FB

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 17, 2009 3:16 pm

I found that named ranges do not work (despite what Microsoft's documentation says). I could only get it to work by retrieving the entire sheet and specifying just the sheet name followed by $:

Let>SQL=select * from [countries$]

Or:

Let>SQL=select * from [sheet1$]

(Depending on the name of the worksheet)

That works for me. I have never got named ranges to work - it always returns nothing.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fuzzbug
Newbie
Posts: 5
Joined: Tue Oct 23, 2007 7:34 pm
Location: Watford, UK
Contact:

please say something helpful

Post by fuzzbug » Fri Apr 10, 2009 7:46 am

I had already tried
Let>SQL=select * from [sheet1$]

but I just tried it again and it works now


thank you
FB

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts