473,382 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

ODBC error in Excel macro, on one particular PC

Baically, myself and the person I sit next to use a shortcut to an Excel file. The Excel file has multiple macros. When office mate opens it, it works fine (ie all macros run, excel file gets data,). When i click on the shortcut, I get an error pop up: Run time error 1004' General ODBC error.

When i click on Debug, VB opens and it shows:

Object = General
Procedure = Get_program_dates
and highlighted in Yellow is: .Refresh BackgroundQuery:=False

I have searched the internet for the error 1004 and found many solutions that dont work. The real strange thing is why it does not work on my machine, but on the guys next to me it does? We have checked that we have the same connections (Data Sources). Is this a problem with something else? Even the guy (not myself) who wrote the code can't figure out why it is not working. I found where someone said it might have to do with dates? But why does it work on his and not mine?

Here is the snippet of code:

Expand|Select|Wrap|Line Numbers
  1. With ActiveSheet.QueryTables.Add(Connection:= _
  2.         "ODBC;DSN=ADW;UID=CurUser;APP=Microsoft Office 2003;WSID=CP040;DATABASE=DataWarehouse;Trusted_Connection=Yes" _
  3.         , Destination:=Range("A1"))
  4.         .CommandText = Array( _
  5.         "SELECT DISTINCT STRAT_All_View.EvSDate" & Chr(13) & "" & Chr(10) & "FROM DataWarehouse.dbo.STRAT_All_View STRAT_All_View" & Chr(13) & "" & Chr(10) & "WHERE (STRAT_All_View.EvSDate>{ts '2005-03-01 00:00:00'})")
  6.         '"SELECT DISTINCT STRAT_All_View.EvSDate" & Chr(13) & "" & Chr(10) & "FROM DataWarehouse.dbo.STRAT_All_View STRAT_All_View" & Chr(13) & "" & Chr(10) & "ORDER BY STRAT_All_View.EvSDate DESC")
  7.         .name = "Query from ADW"
  8.         .FieldNames = True
  9.         .RowNumbers = False
  10.         .FillAdjacentFormulas = False
  11.         .PreserveFormatting = True
  12.         .RefreshOnFileOpen = False
  13.         .BackgroundQuery = True
  14.         .RefreshStyle = xlInsertDeleteCells
  15.         .SavePassword = False
  16.         .SaveData = True
  17.         .AdjustColumnWidth = True
  18.         .RefreshPeriod = 0
  19.         .PreserveColumnInfo = True
  20.         .Refresh BackgroundQuery:=False
Thanks for any help!
Jan 31 '08 #1
5 5012
daniel aristidou
491 256MB
Since he said it might be date...which is possible have you checked you computer date an sync to get correct time + Date....
Also check that the network connection...if the file is found over a network..
Jan 31 '08 #2
Since he said it might be date...which is possible have you checked you computer date an sync to get correct time + Date....
Also check that the network connection...if the file is found over a network..
I checked both ofb these and they are fine. I am wondering if it is a setting on my actual computer? All other macros in other documents work fine..

Thanks for the help Daniel. I appreciate the quick response. Any other suggestions?
Jan 31 '08 #3
kadghar
1,295 Expert 1GB
I think the error comes from the Connection. But it's shown in "refresh" line because there is when excel connects with the data base.

write

Expand|Select|Wrap|Line Numbers
  1. msgbox (.connection)
before you refresh the querytable, this will show you the connection path, so you can check it.

now, what i've seen, is that you have written

"ODBC;DSN=ADW;UID=CurUser;APP=Microsoft Office 2003;WSID=CP040;DATABASE=DataWarehouse;Trusted_Con nection=Yes" _
, Destination:=Range("A1"))

check how 'Trusted_con nection=Yes' has a space between both n's, I'd say you dont have that space in your original code, since this wont even let you run the the macro... but you never know =P.
Jan 31 '08 #4
Killer42
8,435 Expert 8TB
Just on the date theme, it might be worth checking whether both PCs have the same settings for date format.

Also, can you try it on any other PCs? It might be useful to know which one is the "exception".
Feb 1 '08 #5
daniel aristidou
491 256MB
Just on the date theme, it might be worth checking whether both PCs have the same settings for date format.

Also, can you try it on any other PCs? It might be useful to know which one is the "exception".
Go to the regional settings in the control panel and check the date formats
Feb 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
4
by: Dave | last post by:
Hey guys, I have an ODBC problem that has me stumped. I wrote a VBA script to run in Microsoft Excel that pulls data out of an application using that application's ODBC driver and puts it into...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
4
by: weboweb | last post by:
Hello group, I hope I've come to the right place to post my question! I am trying to get the worksheet names from an excel file using ODBC, but for some reason I get SQL_NO_DATA error code...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
2
by: Robert Brown | last post by:
Hi All.. This is a strange one that I hope someone has come across. I have an asp.net application that needs to access a flat file databse via ODBC. I have setup the OBDC DSN and tested it...
6
by: =?Utf-8?B?LnBhdWwu?= | last post by:
how can i write to an excel .xls file using odbc? i've read in several places that its possible but i can't find an example. i have managed to read an excel file using odbc
4
by: jclover | last post by:
I have an excel spreadsheet that is linked to a query in an access database on a shared network drive. There is no security in the database, or the spreadsheet. As of this weekend, the other users...
4
by: MAdcock | last post by:
Hi, I have created an excel program which creates 65 or more (nneds to be unlimited) customised letters for clients. The macro uses VLOOKUP to change the details within the letter and copies /...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.