sample of code needed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could someone point me to a sample of VB code to allow me to have one db open
and access data from a seperate closed db.
Say I have a procedures db open, and I want to call a procedure to access
a server name in a seperate database and get details related to that server
 
Could someone point me to a sample of VB code to allow me to have one
db open and access data from a seperate closed db.

The short way is to use the IN clause in a SQL command:

SELECT COUNT(*)
FROM Sheep IN "c:\otherfolder\otherdatabase.mdb"
WHERE Flock = "Eric"

but if you have to make a number of queries, it's easy enough to open a
foreign database and use it just like the CurrentDB()...


' open the foreign database in current workspace, i.e. using
' same workgroup, uid, and password
dim db as database
set db = opendatabase("c:\otherfolder\otherdatabase.mdb",false, false)

' make a command
dim jetSQL as string
jetSQL = "SELECT COUNT(*) FROM Sheep WHERE Flock = ""Eric"""

' run the command against the foreign database
dim rs as recordset
set rs = db.openrecordset(jetSQL, dbopensnapshot, dbforwardonly)

' and get the answer
msgbox "There are " & rs.fields(0).Value & " sheep"

' tidy up
rs.close
db.close


Hope that helps


Tim F
 
Back
Top