|
-
Apr 19th, 2001, 08:28 AM
#1
Thread Starter
Hyperactive Member
Hey folks,
I'm just starting my first VB project after working in MSAccess. As you can imagine, Im missing my docmd's 
Basically, I was wondering if there is an import command/method/function (kinda like access's TransferText function), or do I have to write my data line by line?
Cheers all
-
Apr 19th, 2001, 08:34 AM
#2
Retired VBF Adm1nistrator
Well what are you importing the data from ?
And then how do you want the data stored once its imported ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 19th, 2001, 08:46 AM
#3
Thread Starter
Hyperactive Member
Well, this one is an import from a .csv file into an MSAccess table.
-
Apr 19th, 2001, 08:55 AM
#4
Retired VBF Adm1nistrator
Okay,
Well to read in data from a file in VB, and then separate values separated by commas into an array you would do this :
Code:
Dim varString As String
Dim varStrArray() As String
Open "c:\something.csv" For Input As #1
Do Until Eof(1)
DoEvents
Line Input #1, varString
varStrArray = Split(varString, ",")
Loop
Close #1
Each iteration through the loop it will read in a new line from the file into the varString variable.
Then it splits the data into an array called varStrArray.
So you would then do something with the data in varStrArray. Perhaps something like this :
Code:
Dim varString As String
Dim varStrArray() As String
Dim i As Long
Open "c:\something.csv" For Input As #1
Do Until Eof(1)
DoEvents
Line Input #1, varString
varStrArray = Split(varString, ",")
For i = 0 To UBound(varStrArray)
Select Case i
Case 0:
RS.Fields("Something 0").Value = varStrArray(i)
Case 1:
RS.Fields("Something 1").Value = varStrArray(i)
Case 2:
RS.Fields("Something 2").Value = varStrArray(i)
End Select
Next I
Loop
Close #1
The above RS and fields bit would be referring to a recordset using DAO.
I dont like database stuff much so Im not too hot on it ...
but most of the above code should do.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 19th, 2001, 09:00 AM
#5
Thread Starter
Hyperactive Member
Thanx man, that was the way I guessed I was gonna have to do it.
Just wondered if there was a nice easy 1-liner like access..... =)
Cheers for your help!
-
Apr 19th, 2001, 09:11 AM
#6
Retired VBF Adm1nistrator
Well there is :
Code:
Just call the JustDoIt() function.
Public Sub JustDoIt()
Dim varString As String
Dim varStrArray() As String
Dim i As Long
Open "c:\something.csv" For Input As #1
Do Until Eof(1)
DoEvents
Line Input #1, varString
varStrArray = Split(varString, ",")
For i = 0 To UBound(varStrArray)
Select Case i
Case 0:
RS.Fields("Something 0").Value = varStrArray(i)
Case 1:
RS.Fields("Something 1").Value = varStrArray(i)
Case 2:
RS.Fields("Something 2").Value = varStrArray(i)
End Select
Next I
Loop
Close #1
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 19th, 2001, 09:22 AM
#7
Junior Member
You wanted a nice one liner, Well here is one.
appAccess.OpenCurrentDatabase databasename 'Open DB
'Import file using table specification for setting
appAccess.DoCmd.TransferText acImportDelim, "Import Specification", _
"Tablename ", FilePathToOpen, True
appAccess.CloseCurrentDatabase
appAccess.Quit
Hope you find this OK
-
Apr 19th, 2001, 09:25 AM
#8
Thread Starter
Hyperactive Member
Heheh, that's kinda cheating, but I like it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|