Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Importing to a MS Access db on a server that doesn't have MS OFFICE

I have created an Access db that has a few macros to automatically delete records, import legacy data, then close itself.  Since I can not put MS Office on our live server I am wondering if I can do this in VB code?

so far for the import section I have written:

dim accImport, db, fso

set accImport = CreateObject("Access.Application")
set fso = CreateObject("Scripting.FileSystemObject")
set db = fso.GetFile("path to my db")

accImport.OpenCurrentDatabase db
accImport.DoCmd.TransferText acImportDelim, "Schema.ini", "table1", "path to the file that gets converted", False, ""

accImport.CloseCurrentDatabase
Set appAccess = Nothing

What I want to know is if this is possible, since I will be manipulating an Access file on a server that doesn't have MS Office installed on it.

Thanks,

ali
0
alialipad
Asked:
alialipad
  • 3
  • 2
1 Solution
 
rvooijsCommented:
Hi,

If you don't have Access installed, you can not create an Access.Application object.
The code you have so far won't work then ...

What you can do is create an ADODB.Connection object.
You can use this object to run queries (including append and delete queries) on your database.

I don't have ewxamples nearby so I can''t help you with the exact syntax but you would get
something like this

set objCon = CreateObject("ADODB.Connection")
objCon.Open " ... not sure here ..."

set objCommand = CreateObject("ADODB.Command")
set objCommand.Connection = objCon
objCommand.Execute "SQL statement here ... "

Sorry I can't help you with the exact code, butÍ'm sure this wil get you further.

Robert
0
 
alialipadAuthor Commented:
Yeah that puts me on the right track thanks, but now I need to figure out how to get the data in the fields, I am importing a .txt file into the db using "~" as a delimiter.  Should I create an array and split up each line with "~"?

ali
0
 
alialipadAuthor Commented:
more the point, I am using this as my looping statement:

While Not textStream.AtEndOfStream
     inLine = Split(textStream.ReadLine, "~")
     Rs.AddNew
     For i = 0 To UBound(inLine) - 1
          Rs.Fields(i).Value = Left(inLine(i), Rs.Fields(i).Size)
     Next i
     Rs.Update
Wend

thanks,

Ali
0
 
rvooijsCommented:
Hi,

Your code seems OK, what is your question ?

Robert
0
 
alialipadAuthor Commented:
as I think about it, I realize that I have arrived at the answer! for you...100 points...ding dong!

ali
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now