How to query a backEnd database from a frontend database with a Sql script

informer

Registered User.
Local time
Today, 05:09
Joined
May 25, 2016
Messages
75
Hi

To query a backEnd database from a frontend database with Sql script, proceed as follows:

Code:
Private Sub Form_Load()
          
        Dim strPathDb As String, strDbName As String, strRsetTable As String, strBackEndLocation As String, strDBPSW As String
         
         strPathDb = Application.CurrentProject.Path & "\"
         strDbName = "test_be.accdb"
     
         strBackEndLocation = strPathDb & strDbName
         
         strDBPSW = ""
         Me.RecordSource = "SELECT * FROM tblTest IN'' [MS Access;PWD=" & strDBPSW & ";database=" & strBackEndLocation & "]"         
     end sub

Or go there http://www.utteraccess.com/forum/index.php?showtopic=2037433&view=findpost&p=2601389
 
or in a public module have

Code:
 dim BE as DAO.Database
  
 public function openBE() 'call when db opened
     Set BE = DBEngine.OpenDatabase(DBPath , 0, 0, "MS Access" )
 end function
and in your form load event you just need

Code:
me.recordset=BE.openrecordset("SELECT ....")
benefit is the back end is open persistently so lower time overhead on getting the records, whereas your method isn't, although fine for occasional access to other data.
 

Users who are viewing this thread

Back
Top Bottom