LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Link to database

My company uses oracle databases. After I set up the connection via Data
Sources (ODBC), what is the best way to access information from the database
using VBA? I used to have the database locally, but I want to make it
available to multiple users. I've recorded an "import external data" sub,
but I can't make heads or tails out of the code. What's the best way to do
this? Thanks for any help!

What I had:
GetDBLocation = Worksheets("SETTINGS").Range("T2").Value
Set InitDatabase = OpenDatabase(GetDBLocation)

Recorded macro from Import External Data-New Database Query (mind wrapping):

Sub Macro1()

With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _

"ODBC;DSN=OSM;UID=OKJ/OKJ;;DBQ=CPIDOSMP;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FR C=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSucce ssful;NUM=N" _
), Array("LS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000; TLO=O;")),
Destination:= _
Range("A1"))
.CommandText = Array( _
"SELECT AK_FOREIGN_KEY_COLUMNS_V.ROW_ID" & Chr(13) & "" & Chr(10) &
"FROM TKR.AK_FOREIGN_KEY_COLUMNS_V AK_FOREIGN_KEY_COLUMNS_V" & Chr(13) & "" &
Chr(10) & "ORDER BY AK_FOREIGN_KEY_COLUMNS_V.ROW_ID" _
)
.Name = "Query from OSM"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
--
-SA
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Link to SQL Database jgrebe Excel Worksheet Functions 0 July 25th 07 01:42 PM
Updating link to database w/o breaking the link A.Gates Excel Programming 0 January 26th 07 06:55 PM
Moved database, how do I change link to the database in excel Toastrack Excel Discussion (Misc queries) 0 October 20th 06 09:36 AM
Database Link Ed Excel Discussion (Misc queries) 2 April 24th 06 06:43 AM
Pivot link to database John[_60_] Excel Programming 0 November 17th 04 07:43 PM


All times are GMT +1. The time now is 03:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"