Steven,
You could store the location of the backend in a local table in the front end. Create a new table called tblPreferences and set the primary key field to a long integer and set the validation rule = 1. When entering the first record enter a 1 in the primary key field. This will force the table to only ever have a single record. I put all my system level variables in this table. Add one to store the location of the backend, something like 'BackendLocation'.
When the database opens you could set a variable to that location.
Option Database Compare
Option Explicit
Public g_BackendLocation as String
Function SetBackEndLocation as Boolean
Dim strSQL as String
Dim rstTemp as DAO.Recordset
strSQL = "SELECT BackendLocation from tblPreferences"
set rstTemp = currentdb.openrecordset(strSQL)
if rstTemp(0) = "" Then
msgbox "No backend location"
Else
g_BackendLocation = rstTemp(0)
SetBackEndLocation = True
end if
rstTemp.close
set rstTemp = nothing
end sub
Once you have this variable you can use it like this.
Sub GetSomeData()
Dim strSQL as string
Dim rstTemp as DAO.Recordset
If g_BackendLocation = "" then
If not SetBackEndLocation then
Msgbox "There was a problem locating the backend database."
Exit sub
End if
End if
strSQL = "SELECT * FROM SomeTable IN '" & g_BackendLocation & "'"
set rstTemp = CurrentDB.OpenRecordset(strSQL)
'Do something here with the records.
'
'
rstTemp.Close
set rstTemp = nothing
End Sub
I wrote this code from memory. It should work unless I have some typos. Also, make sure you have a reference to DAO.
Hope this helps,
Mike
PS: Will Code for Food
-----Original Message-----
From: Wrox P2P Forum Subscriptions [mailto:donotreply@wrox.com]
Sent: Sunday, June 29, 2003 4:33 PM
To: Michael Stalford
Subject: [Access] Backend as a constant
Hello Dataman,
Forum member Steven has posted a new topic to the Access forum.
You are being notified because you are subscribed to the Access forum.
Topic: Backend as a constant
Message:
------------------------------------------------------
I've got a database which is split between front and back end.
For various reasons, which I need not go into (suffice it to say that RWOP is one of the reasons), I link the files not through linked tables, but through queries and code.
The big problem is that this means the location is hard-coded in a million different places, and while a Find/Replace works for the code, it doesn't work for queries, and it isn't very elegant.
Does anyone know a way that I can declare the backend file as a constant, and then refer to it as that constant for queries and code?
Basically what I want to do is something along the lines of this:
Code:
Public Constant BackEndDB = "\\server\share\backend.mdb"
Then have the SQL for the queries be something like:
Code:
SELECT * FROM Table1 in BackEndDB;
And would also allow me to refer to the file as BackEndDB in my code.
Any help with this would be greatly appreciated.
Thanks
Steven
There are 10 kinds of people in the world - those who understand binary - and those with friends
------------------------------------------------------
You can view this posting at:
http://p2p.wrox.com/topic.asp?TOPIC_ID=1177
You can reply to this posting at:
http://p2p.wrox.com/post.asp?method=...177&FORUM_ID=5