|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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$`" |
|
#2
|
||||
|
||||
|
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$`" |
|
#3
|
|||
|
|||
|
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. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Replacing the directory with a name |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|