473,386 Members | 1,720 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,386 software developers and data experts.

Dynamic Link to CSV file

365 100+
Good morn all,

i want to be able to link periodically to a CSV file so that i can extract some data, i imagine that i want to establish a link, query the data and then delete the link once completed, how would i do this from VB?

a direct query would surfice if that can be done?

any ideas on the initial code?

Dan
Feb 17 '09 #1
15 5838
NeoPa
32,556 Expert Mod 16PB
I can't find how to link a table from VBA (unfortunately). The closest I got was :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.RunCommand(acCmdLinkTables)
I'm pretty sure this is not an adequate answer, and I could find any further explanations within the Help system.

I'll continue to monitor as I'm interested in seeing an answer to this one.
Feb 17 '09 #2
Dan2kx
365 100+
ill just add that the CSV file will have a header row.. if that makes any difference
Feb 17 '09 #3
NeoPa
32,556 Expert Mod 16PB
@Dan2kx
Only if we can find a way to invoke the LinkTable process. Then it may ;)
Feb 17 '09 #4
Dan2kx
365 100+
Hello, i found this on the net, couldnt get it to run past the second Dim, i editted my paths in, this is the original,

Expand|Select|Wrap|Line Numbers
  1. Private Sub LinkTable(psTable As String, psFromPath As String, _
  2.   psToPath As String)
  3.  
  4. Dim cnn As ADODB.Connection
  5. Dim cat As ADOX.Catalog
  6. Dim tbl As ADOX.Table
  7. Dim sShortPath As String
  8.  
  9.     'get short path name of the source database
  10.     sShortPath = Space(255)
  11.     Call GetShortPathName(psFromPath, sShortPath, 255)
  12.     sShortPath = Trim$(sShortPath)
  13.     sShortPath = Left$(sShortPath, Len(sShortPath) - 1)
  14.  
  15.     'connect to the target database
  16.     Set cnn = New ADODB.Connection
  17.     With cnn
  18.         .Provider = "Microsoft.Jet.OLEDB.4.0"
  19.         .Properties("Data Source") = psToPath
  20.         .Open
  21.     End With
  22.  
  23.     Set cat = New ADOX.Catalog
  24.     Set cat.ActiveConnection = cnn
  25.  
  26.     'link table
  27.     Set tbl = New ADOX.Table
  28.     With tbl
  29.          .Name = psTable
  30.          Set .ParentCatalog = cat
  31.          .Properties("Jet OLEDB:Create Link") = True
  32.          .Properties("Jet OLEDB:Link Datasource") = sShortPath
  33.          .Properties("Jet OLEDB:Remote Table Name") = psTable
  34.  
  35.          On Error Resume Next
  36.          cat.Tables.Delete psTable
  37.          On Error GoTo 0
  38.  
  39.          cat.Tables.Append tbl
  40.     End With
  41.     Set tbl = Nothing
  42.  
  43.     'release references
  44.     cnn.Close
  45.     Set cnn = Nothing
  46.  
  47.     Set cat = Nothing
  48.  
  49. End Sub
mean anything to anyone?
Cheers
Dan
Feb 17 '09 #5
NeoPa
32,556 Expert Mod 16PB
So, it failed on line #5. What was the error message?

PS. I suspect it's related to the ADOX, but lets get the info to work with first.
Feb 17 '09 #6
Dan2kx
365 100+
Just says
Comple Error:

User-defined type not defined

Think you are right doesnt like any of the ADOX items
Feb 17 '09 #7
NeoPa
32,556 Expert Mod 16PB
Have you got a reference set up to Microsoft ADOX (This would be necessary for it to work of course)?
Feb 17 '09 #8
Dan2kx
365 100+
nope, how is that done?
Feb 17 '09 #9
NeoPa
32,556 Expert Mod 16PB
Open up your project in Access, then take the following steps :
  1. Alt-F11 to open and switch to the VBA window.
  2. Select Tools / References... to see and select the references.
  3. Review the ticked ones at the top.
  4. If Microsoft ADOX is not there then scroll down the list until you find it (in my 2003 installation it is Microsoft ADO Ext. 2.8 for DDL and Security).
  5. Click in the box to select it.
Now try recompiling the code and see where you get.
Feb 17 '09 #10
Dan2kx
365 100+
OK got it, sort of, line 39 says table already exists, i think it must be creaing in the source DB (which cant be right can it?) and line 36 deleted my table, thankfully its not the live DB, phew

Dan
Feb 17 '09 #11
Dan2kx
365 100+
My bad, had the other wrong path in line 19, it seems to work, not tried a CSV yet.....

Dan
Feb 17 '09 #12
Dan2kx
365 100+
Error message says it needs a TableID

OK, back to the drawing board
*sigh*
Feb 17 '09 #13
Dan2kx
365 100+
OK, i give up, i found an alternative using make table SQL to use in VB, i can easily delete this table after processing:

Expand|Select|Wrap|Line Numbers
  1. SELECT * INTO " & Input1 & " FROM [Text;DATABASE=H:\Bin\;HDR=Yes]." & Input1 & ".csv;
would still be interested if anyone can resolve my OP, but for now i have my problem "solved".

Thanks to all,
Dan
Feb 18 '09 #14
NeoPa
32,556 Expert Mod 16PB
Sorry Dan. I don't know the code for linking tables.
Feb 18 '09 #15
Dan2kx
365 100+
its ok NeoPa, you have helped me enough already, the code i found on the net (and posted) does successfully links tables from another DB, which may present a use for me in the future, and anyone else on the forum of course, it just doesnt work for the CSV/TXT file problemo.

Thanks again

Dan
Feb 18 '09 #16

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

Similar topics

4
by: Daniel Keller | last post by:
Hello! I'm trying to set up a page system using "dynamic" SSI. That means that I normally use the following on my website: <!--#include virtual="file.inc" --> Now I want to make this...
0
by: UtilityWarrior | last post by:
If you use Visual Basic 6 or VB.net and want to create PDFs from images royalty free then this DLL is for you. The Image to PDF Dynamic Link Library (DLL) will convert one or more images (JPEG,...
3
by: Daves | last post by:
what would be the easiest way to create a dynamic css file to link to eg .... <head> <link type="text/css" rel="Stylesheet" href="lis.aspx" /> </head> .... this one quite clumsy since...
2
by: JWL | last post by:
Hi I need to create a bunch of sites with slightly dynamic CSS. Basically, all the image paths in the CSS need to be dynamic, depending on the values of certain ASP variables. I can think of...
1
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is...
1
by: zpinhead | last post by:
I am unable to get my downloaded extension from pecl to link up with php properly. seems like the php.so I could not use pear install http. pear claimed the extension was already installed....
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
1
by: jeudi33 | last post by:
Hi, I previously posted my question but it was wrongly labeled. So here it is again: in Flash, I created a dynamic field that called a txt file. In this text, I would like to have a link that...
12
by: prashant | last post by:
hi, i am trying to create an xml tag ref to hold link.php?id=1; or link.php?id=2 and so on. I want the links for all the fields(id) in the databse so that when i call them in my html page for...
4
by: henry | last post by:
Folks: Using Dreamweaver CS3... Consider a home page, "index.php" which conditionally REQUIREs one of 'N' HTML files of pure content. All site styles are specified in a master CSS file,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.