Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 29th, 2003, 06:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default Backend as a constant

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
__________________
<hr noshade size=\"1\"><i><font color=\"blue\">I am a loud man with a very large hat. This means I am in charge</i></font id=\"blue\">
 
Old June 29th, 2003, 11:49 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Path to database backend Clive Astley Beginning VB 6 3 January 12th, 2007 01:29 AM
Access MDB with SQL Backend ashg657 Access 2 July 18th, 2006 12:54 PM
Backend Issues Aaron Edwards Access 3 August 26th, 2005 10:50 PM
Backend security simmyboy Access 3 August 22nd, 2005 02:42 AM
Linking to backend Clive Astley Access VBA 6 April 1st, 2004 01:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.