Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1068503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:17:47+00:00 2026-05-16T20:17:47+00:00

Hey all, have been working on designing a new database for work. They have

  • 0

Hey all, have been working on designing a new database for work. They have been using Excel for their daily reports and all the data is stored in there, so I decided to have the back-end of the database in Access and the front-end in Excel, so any analytical work can be easily performed once all the data has been imported into Excel.

Now I’m fairly new to VBA, slowly getting used to using it, have written some code to transfer one of the calculated tables from Access to Excel:

Option Explicit

Public Const DataLocation As String = "C:\Documents and Settings\Alice\Desktop\Database\TestDatabase21.accdb"

Sub Market_Update()
    Call ImportFromAccessTable(DataLocation, "Final_Table", Worksheets(2).Range("A5"))
End Sub

Sub ImportFromAccessTable(DBFullName As String, TableName As String, TargetRange As Range)

    Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer

    Set TargetRange = TargetRange.Cells(1, 1)
    ' open the database
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBFullName & ";"
    Set rs = New ADODB.Recordset
    With rs
        ' open the recordset
        ' .Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable

        ' all records
        .Open "SELECT * FROM Final_Table", cn, , , adCmdText
        ' filter records

        For intColIndex = 0 To rs.Fields.count - 1 ' the field names
            TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
        Next
        TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data

    End With
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub

Sub Company_Information()

   Dim companyName As String

On Error GoTo gotoError

   companyName = Application.InputBox(Prompt:="Enter Company Name", _
                           Title:="Company Name", Type:=2)                  

    Exit Sub 'Don't execute errorhandler at end of routine

gotoError:
    MsgBox "An error has occurred"

End Sub

The above code works fine and pulls up the desired calculated table and places it in the right cells in Excel.

I’ve got two problems that I’m having trouble with; firstly I have some cell-formatting already done for the cells where the data is going to be pasted into in Excel; I want it to apply the formatting to the values as soon as they are pasted in Excel.

Secondly; I have an add-on for Excel which updates some daily Stock Market values; these values need to be transferred into Access at the end of each working day, to keep the database maintained, I tried some code but have been having some problems with it running.

The code for this part can be seen following:

Sub UPDATE()

   Dim cnt As ADODB.Connection
   Dim stSQL As String, stCon As String, DataLocation As String
   Dim stSQL2 As String

   'database path - currently same as this workbook
   DataLocation = ThisWorkbook.Path & DataLocation
   stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
   "Data Source=" & DataLocation & ";"
   'SQL code for GL Insert to Access
   stSQL = "INSERT INTO Historical_Stock_Data SELECT * FROM [Portfolio] IN '" _
   & ThisWorkbook.FullName & "' 'Excel 8.0;'"

   'set connection variable
   Set cnt = New ADODB.Connection
   'open connection to Access db and run the SQL
   With cnt
        .Open stCon
        .CursorLocation = adUseServer
        .Execute (stSQL)
   End With
   'close connection
   cnt.Close

   'release object from memory
   Set cnt = Nothing

End Sub

I get the following error with this.

Run-time Error '-2147467259 (80004005)'

The Microsoft Jet database engine cannot open the file 'Cocuments and Settings\Alice\Desktop\Database'. It is already opened exclusively by another user or you need permission to view its data.

I’m fairly new to databases, VBA and Access so any help would be greatly appreciated.

Also I have been told that the above method of having an Excel front-end and Access back-end is not recommended but alot of the analysis they conduct is done through Excel, and the charts feature in Excel is much better than Access in my experience atleast; and that is also one of the requirements for this project.

Thank you advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:17:47+00:00Added an answer on May 16, 2026 at 8:17 pm

    Solution to your first problem:
    Sorry to be the bearer of bad news, but your entire first module is unnecessary. Instead, try:

    1. Go to Data->Import External Data->Import Data, select your Access file, select your table, and presto! done!
    2. Right-click on your new “External Data Range” to see a number of options, some related to formatting. You can even keep the original cell formatting and just update the values. I do this all the time.
    3. To update the Excel data table later, there is a “External Data Range” toolbar that allows you to refresh it as well as a “refresh all” option to refresh every table in the Excel file. (You can also automate this thru code. It’ll take some trial and error, but you’re definitely up to the task)

    Regarding your second problem
    I’ve never used it, but there is also a “New Web Query” option in there as well. I assume it can be manipulated and updated the same way.

    And lastly
    Your choice of the Excel front-end and the Access back-end sounds good for your needs. It gets the data to your analysts in a medium they are familiar with (Excel) while keeping the calculations out of the way in Access. Technically, you could try putting all your calculations in Excel, but that might the Excel file much bigger and slower to open.

    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.