On Fri, 06 Oct 2006 at 13:45:54, Simon Edkins wrote:
My question is: how do I connect to the Access file at run time,
without having to go through
the Select Data Source wizard every time.
Here is a sample of the code I'm trying to run from a button's action
event:
dim AccessDB as ODBCDatabase
dim rs as RecordSet
dim SQLString as String
dim RecCount as Integer
dim i as Integer
AccessDB = new ODBCDatabase
Accessdb.DatabaseName = "WeighingDB"
AccessDB.DataSource = "" ????
if AccessDB.Connect then
SQLString = "Select Study_Number from Studies;"
rs = AccessDB.SQLSelect(SQLString)
RecCount=rs.RecordCount
if RecCount> 0 then
rs.MoveFirst
for i = 1 to RecCount
Listbox1.AddRow
rs.Field("Study_Number").StringValue
rs.MoveNext
next
end if
else
MsgBox"Connection Failed"
end
The typical format for a db.DataSource connection string is:
db.DataSource = "DSN=my_dsn;UID=my_user_id;PWD=my_password"
So, in your case, you should probably use:
AccessDB.DataSource = "DSN=WeighingDB.dsn"
I'm not sure if the ODBC plugin supports file-based DSN's on Windows
- I know they're not supported on the Mac.
If you don't want to use a DSN at all, you could use what is known as
a "DSN-less" connection:
db.DataSource = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:
\my_access_db.mdb"
or for the Mac:
db.DataSource = "DRIVER=/Library/ODBC/Actual Access.bundle/Contents/
MacOS/ataccess.so;DBQ=/Users/admin/Nwind.mdb"
Also, I should point out that it's totally acceptable for a driver to
only support "forward-only" cursors. When this is the case,
rs.RecordCount will always return -1, and rs.MoveFirst will return an
error. I don't know if the MS Access driver is forward-only, but you
might want to assume that it is for partability's sake. Or, better
yet, check it's cursor support with:
Dim forwardOnly As Boolean
If db.GetInfo(ODBCConstant.SQL_DYNAMIC_CURSOR_ATTRIBUTES1)> 0 Then
forwardOnly = false
Else
forwardOnly = true
End If
Jonathan Monroe
Actual Technologies - ODBC for Mac OS X
www.actualtechnologies.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>