Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 8th, 2005, 11:55 AM
tigre tigre is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 tigre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 41 sec
Reputation Power: 0
Question Input filename using txtbox with Excel Query

I have the following code for importing data from a CVS file into Excel. This works file for a file of a given name (book7) as in example 1. I want to make the macro flexible so that users can enter the file name, which is in the same directory. I included a textbox (TXTFILE) to input the file name and made modifications to the code (Example 2) expecting it obtain the file name from the textbox. Instead I get the following error when attempting to execute the macro. It stops at the line “With Selection.QueryTable”



RUN TIME ERROR ‘1004’

APPLICATION-DEFINED OR OBJECT-DEFINED ERROR.



Can any one point me in the right direction of resolving this error .



Thanks



Tigre



Example 1 (this works)

' rawdata Macro

' Macro Date 2/3/2005 (Tigre)

'This macro imports raw data from CVS file created by the analyzer



'

With Selection.QueryTable

.Connection = Array(Array( _

"ODBC;DSN=Excel Files;DBQ=C:\Documents and Settings\Tigre\Desktop\Book7.xls;DefaultDir=C:\Doc uments and Settings\Tigre" _

), Array("Tigre\Desktop;DriverId=790;MaxBufferSize=2048;Page Timeout=5;"))

.CommandText = Array( _

"SELECT `Sheet1$`.Index, `Sheet1$`.Time, `Sheet1$`.`Ch 1 Raw Data`, `Sheet1$`.`Ch 1 Load`, `Sheet1$`.`Ch 1 Energy`, `Sheet1$`.`Ch 1 Velocity`, `Sheet1$`.`Ch 1 Deflection`, `Sheet1$`.F8, `Sheet1$`.Time1" _

, _

", `Sheet1$`.`Ch 1 Load1`" & Chr(13) & "" & Chr(10) & "FROM `C:\Documents and Settings\Tigre\Desktop\Book7`.`Sheet1$` `Sheet1$`" & Chr(13) & "" & Chr(10) & "WHERE (`Sheet1$`.Time>=0) AND (`Sheet1$`.`Ch 1 Load`>=0)" _

)

.Refresh BackgroundQuery:=False

End With

End Sub





EXAMPLE 2 ( this returns error ‘1004’)

Sub rawdatabyfile()

'

' rawdata Macro

‘Macro Date 2/3/2005 (Tigre)



‘This macro imports raw data from CVS file created by the analyzer



Dim txtfile



With Selection.QueryTable

.Connection = Array(Array( _

"ODBC;DSN=Excel Files;DBQ=C:\Documents and Settings\Tigre\Desktop\txtfile;DefaultDir=C:\Docum ents and Settings\Tigre" _

), Array("tigre\Desktop;DriverId=790;MaxBufferSize=2048;Page Timeout=5;"))

.CommandText = Array( _

"SELECT `Sheet1$`.Index, `Sheet1$`.Time, `Sheet1$`.`Ch 1 Raw Data`, `Sheet1$`.`Ch 1 Load`, `Sheet1$`.`Ch 1 Energy`, `Sheet1$`.`Ch 1 Velocity`, `Sheet1$`.`Ch 1 Deflection`, `Sheet1$`.F8, `Sheet1$`.Time1" _

, _

", `Sheet1$`.`Ch 1 Load1`" & Chr(13) & "" & Chr(10) & "FROM `C:\Documents and Settings\Tigre\Desktop\txtfile`.`Sheet1$` `Sheet1$`" & Chr(13) & "" & Chr(10) & "WHERE (`Sheet1$`.Time>=0) AND (`Sheet1$`.`Ch 1 Load`>=0)" _

)

.Refresh BackgroundQuery:=False

End With

End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Input filename using txtbox with Excel Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT