Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old March 16th, 2004, 07:23 AM
nicjuan nicjuan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Singapore
Posts: 6 nicjuan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Replacing the directory with a name

Hi,
I am writing an import program which is almost completing except for one part.My purpose of the import program is to import excel spreadsheet into a server,the problem i encoutered is in order to import different excel spreadsheet,i always have to change the directory path in the query 'D:\pd2\Q181_20.xls' to example 'D:\pd2\Q181_25.xls',may i know how to replace the directory path so that i can select any excel spreadsheet without changing the directory path all the time?
Please help me.Thank You


selectStudInfo = "Select Distinct [Acad Prog],ID,Name from `D:\pd2\Q181_20.xls`.`QUERY$` `QUERY$`"

Reply With Quote
  #2  
Old March 16th, 2004, 08:48 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,738 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 h 34 m 28 sec
Reputation Power: 443
You could do it something like this
Code:
Dim excelDir As String

excelDir = "D:\pd2\"

selectStudInfo = "SELECT DISTINCT [Acad Prog], [ID], Name FROM '" & excelDir & "Q181_20.xls`.`QUERY$` `QUERY$`"


or if you only want to change the last 2 numbers in the spreadsheet, you can do it like this.
Code:
Dim excelDir As String

excelDir = "D:\pd2\Q181_"

selectStudInfo = "SELECT DISTINCT [Acad Prog], [ID], Name FROM '" & excelDir & "20.xls'`.`QUERY$` `QUERY$`"

Reply With Quote
  #3  
Old March 17th, 2004, 09:42 AM
nicjuan nicjuan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Singapore
Posts: 6 nicjuan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question REplacing...

Thanks but what if the directory path is not exactly the same all the time? or if the file name is different?How do i make it the same as long as it can search for any excel file in the drive?
Example:
C:\vb\e180.xls
C:\pd1\q181_02.xls
D:\pd2\b181_24.xls
D:\q181_25.xls

I know that most people will not save the same type of file seperately but i am confused about it.Please help.

The below is actually what i have written for part of my program.

Function GetDataAndInsertStudInfo()
Dim sql, selectStudInfo, Insert, Update As String
Dim PROG, STUD_ID, STUD_NAME As String
Dim MOD_ID, CLASS_SECT, COMPONENT, Location, DAY, ST_TIME, ED_TIME

selectStudInfo = "Select Distinct [Acad Prog],ID,Name from `D:\pd2\Q181_20.xls`.`QUERY$` `QUERY$`"
rs.Open selectStudInfo, cn, adOpenDynamic

If Not rs.EOF Then

Do While Not rs.EOF

PROG = rs![Acad Prog]
STUD_ID = rs!ID
STUD_NAME = rs!Name

Insert = "Insert into studinfo values('" & PROG & "','" & STUD_ID & "','" & ReplaceQuotes(STUD_NAME) & "')"
Set cmd = New ADODB.Command
cmd.ActiveConnection = cn2
cmd.CommandText = Insert
cmd.Execute

rs.MoveNext
Loop
MsgBox "Completed loading data into studinfo", vbInformation

Else
MsgBox "............................", vbOKOnly


End If

rs.Close
Set rs = Nothing
End Function

Last edited by nicjuan : March 17th, 2004 at 12:05 PM.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Replacing the directory with a name


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway