ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SQL-Query from a textfile? (https://www.excelbanter.com/excel-programming/300729-sql-query-textfile.html)

Stift[_30_]

SQL-Query from a textfile?
 
Hi everyone, I really have a difficult question and dunno if it's
possible.Let me explain what I want.


I want to create a userform with VBA in Excel where a user can brows
to some textfiles(or other files).In the text file there will be
SQL-query code. When user selected the file it must run the Query an
store the result of the query in a few cells.

Please reply I've you can help me creating a beginning (or even mor
:) )

Hope you can help me,


GreetZ from Stif

--
Message posted from http://www.ExcelForum.com


nathan

SQL-Query from a textfile?
 
It is possible my friend, i have assumed you are running the SQL from an access db

Here goe

Sub TXT_Sq

dim sql, strSQL, fname as strin
dim dbs as databas
dim rst as recordse

fname = "sqltextfile

open fname for input as #

input #1,strSQ

close #

Set wrkjet = CreateWorkspace("", "admin", "", dbUseJet) ' Create workspace to handle the DB
Set dbs = wrkjet.OpenDatabase("AccessDatabaseName.mdb", True) ' Open the DBS, put in your db filenam

set rst = dbs.openrecordset (sql) ' open recordset with sq

range("a1").copyfromrecordset rs

dbs.clos

end su

Any probs leave a note on here and i'll do my best to hel

nath

Stift[_31_]

SQL-Query from a textfile?
 
No I won't use Access, But Excel and get data from a SQL-DB

--
Message posted from http://www.ExcelForum.com


Stift[_32_]

SQL-Query from a textfile?
 
Where do I have to put the code in? Behind a CommandButton or in m
Userform.Initiate or what ?

Where do I have to put te txt files.

Sorry I don't have very much experience with VBA

--
Message posted from http://www.ExcelForum.com


nath

SQL-Query from a textfile?
 
If you want it to happen on a command button click, then put it behind the command button. If you want it to happen when you opent the form, then put it on the initialize. Are you querying SQL server?

Stift[_33_]

SQL-Query from a textfile?
 
~× wrote:
*If you want it to happen on a command button click, then put i
behind the command button. If you want it to happen when you open
the form, then put it on the initialize. Are you querying SQ
server? *


No I'm Querying and Oracle D

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com