I have written code that joins two table in access, using criteria supplied from drop down lists in Excel and then returns the data to a specific location on the spreadsheet (titles already on the sheet).
This works fine on my box and others with MS Access on the machine, but the purpose of writing this was to give people (associates) that don't have MS Access on their machines (which is most of them) to be able to do simple queries to the database.
When we try to run this on a machine without MS Access, we are getting the error message
"Compile Error: Can't find project or library."
Since this works fine on any machine so far that has Access, but not the others I am wondering if this is not possible without the actual Access software. Any help or insight would be appreciated.
you need to use ADO and the "jet" provider. This will allow you to query an access database without having access installed
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set objRecordset=Server.CreateObject("ADODB.recordset")
objRecordset.activeconnection = conn
objRecordset.source = "select * from table where field1 = 'asdf'"
objRecordset.open
'do you work here
objRecordset.close
conn.close
Related
Hi there hopefully there is a fix for this but I my ms access program crashed before it could finish a clean up of the data. Its now hit its 2GB maximum and wont open anyone know what do here? I just need it to drop all the data in the columns the thing of value are the queries and what order they are in.
Just get the error Cannot Open database''. It may not be a database that your application recognises, or the file may be corrupt. It gives me that twice.
its in an .accdb format so that shouldnt be a reading issue
Cheers.
Try running a compact and repair directly from the DAO database engine without opening the file in Access
You can use the following code from any VBA-enabled application or a VBScript file (it's designed for VBScript files, but you have to match bitness with your Access application, see this post, but should run fine from Excel as well)
Dim wShell, oExec, sFileSelected
Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
CreateObject("DAO.DBEngine.120").CompactDatabase sFileSelected, Left(sFileSelected, Len(sFileSelected) - 6) & "Compacted.accdb"
That should copy over everything from your corrupt database while compacting it. It creates a new file, with your current filename and Compacted appended to it.
Currently we use a windows 2003 (IIS 6.0) server with SQL Server 2008 R2 that runs perfectly a asp classic code. We are migrating to windows 2016 server with the same version of SQL Server. In most of the code it was necessary to put the full database path. The original that works on the other server, e.g.:
SELECT * from File
when changing to
SELECT * from [TABLE].[dbo].[File]
the new server can execute and read correctly.
In the part that the code itself has the legible queries is easy to understand. I do not know the asp classic well and the original code has variables with the same table name so I do not know if the called code item is actually the table or the variable.
I think it's something from the environment to set up. Would it be possible to resolve this without having to change the whole code?
I try to understand the error from logfile from IIS.
Maybe someone have the same situation, I solve this change the DSN connection (ODBC)
Dim rs
Dim conexao
Set conexao = Server.CreateObject("ADODB.Connection")
conexao.Open "DSN=database","sa","password1234"
I change the last line to use Provider too like example:
conexao.Open "Provider=SQLNCLI10;Server=nameserver\nameinstance;Database=namedatabase;UID=sa;PWD=password1234;"
I have a publicly accessible ms access file - Frontend.accdb for which all tables are linked to another protected ms access database called Data.accdb. An import job is defined in the data.accdb which brings data into the data.accdb which will be updated to Frontend.accdb when opened.
I want to add this import job in my frontend.accdb so that by clicking a button in the frontend.accdb, data.accdb gets refreshed and the tables inside Frontend.accdb is populated with fresh data.
If the back-end tables are linked in the front-end, then you should move the macros to the front-end database to operate on the linked tables.
You can use the shell command as discussed here
How to programatically call a macro in a different (ie. external) Access database using VBA?
but this is likely to complicate matters with regard to making sure that the macro has run correctly and other error trapping.
You could open the backend database from the frontend and run the macro, using an 'Application' object.
Dim appAccess As New Access.Application
'Opening backend database
appAccess.Visible = False 'This can only be here once everyone has trusted the
appAccess.OpenCurrentDatabase "PathtoBackend" & "\data.accdb"
'Time acknowledge the Trust popups if they haven't trusted the db
Do
Sleep 1000 'Assumes you have the Win API Sleep command available.
DoEvents
Loop While Not appAccess.CurrentProject.IsTrusted
appAccess.Run "Import Data Macro Name"
appAccess.CloseCurrentDatabase
appAccess.Quit
OR
Move the entire table update macro to the front end, and push the data from the source to the frontend, to the linked tables in the backend using TransferDatabase.
'Bunch of code that builds the DAO or ADO objects from the source data
Docmd.TransferDatabase acLink, , "PathToBackend" & "\data.accdb", acTable, "FrontEndTableNameContainingSourceData", "BackendTableNameDestination", , )
Edit: The answer to this question can be found within the comments of the accepted answer.
I am attempting to open an Access database from a button click within my excel file. I currently have this code:
Private Sub bttnToAccess_Click()
Dim db As Access.Application
Set db = New Access.Application
db.Application.Visible = True
db.OpenCurrentDatabase "C:\Users\wcarrico\Desktop\wcarrico-CapstoneFinalSubmission.accdb"
End Sub
This seems to work briefly and then Access shuts down almost immediately. If it matters, the Access file has an AutoExec macro that runs through a few tests itself on open.
Don't try to open the Access application then; just create a connection object using one of the Data Access technologies:
- OLE-DB or
- ODBC.
Google "ODBC Connection strings" or "OLE-DB Connection Strings" to get details depending on your particular configuration (and Access filetype).
Probably ADODB is the easiest current library to use for your data access.
Update:
Try Importing the data from Access then using the Data -> From Access wizard. Yu can always use the Macro recoding facility to automatically generate some VBA code for you, that will create some infrastructure for you; I use this regularly when exploring new portions of the VBA object model.
Update - Final resolution of problem, from comments below
That may be because the variable goes out of scope; move the declaration of db outside the function, to module level
The code started Access by creating an application instance assigned to an object variable. At the end of the procedure, the variable went out of scope so Access shut down.
You accepted an answer to use a module-level variable for the Access application instance. In that case, Access remains running after the procedure ends. However if the user exits Excel, Access will close down too.
If the goal is to start Access and leave it running until the user decides to close it, just start Access directly without assigning the application instance to an object variable (Set db = New Access.Application). That db variable would be useful if your Excel code needed it for other purposes. However, it's actually only used to open the db file.
You can use the Run method of WScript.Shell to open your db file in an Access session.
Private Sub bttnToAccess_Click()
Const cstrDbFile As String = "C:\Users\wcarrico\Desktop\wcarrico-CapstoneFinalSubmission.accdb"
Dim objShell As Object
Set objShell = CreateObject("WScript.Shell")
objShell.Run cstrDbFile
Set objShell = Nothing
End Sub
I know this is an old thread, but you will get this error in Excel VBA if you are trying to open an Access database, but you do not have two specific References clicked. (Tools, References on the VBA Editor screen). You need to click 'Microsoft Access 15.0 Object Library' and 'Microsoft ActiveX Data Objects 6.1 Library'.
Remove the New declaration then it works
Actually it is pretty straightforward:
Private Sub bttnToAccess_Click()
db = DBEngine.OpenDatabase("C:\Users\wcarrico\Desktop\wcarrico-CapstoneFinalSubmission.accdb")
End Sub
For this to work you need to declare db as Database at the Module level.
Dim db As Database 'Requires reference to the Microsoft
'Access Database Engine Object Library
We have an old Access 2000 database that we need to pull data from and store it into a text file via a web interface that has to run every 20 minutes. I have spent hours and hours searching for a correct connection string without anything working.
I even used Dreamweaver's point-and-click solution and was able to get it to connect and pull data with a System DSN on my local machine, but it shows a 500 Internal Server Error when I upload it to the testing server (both the local and the testing server System DSNs have the same name). (For clarification to die-hard programmers, I am a developer and am using Dreamweaver because I have no idea what I'm doing with ASP.)
I created a System DSN on the testing server (win server 2008), but it doesn't seem to work. I don't know if it's something with the VB code I'm writing or an issue with the DSNs. Could I please get some help with this, my deadline for this is tomorrow morning! (If I don't meet the deadline, major systems in our business will not work!)
Dreamweaver Connection:
Dim MM_LocalDb_STRING
MM_LocalDb_STRING = "dsn=Db;"
Dim Students
Dim Students_cmd
Dim Students_numRows
Set Students_cmd = Server.CreateObject ("ADODB.Command")
Students_cmd.ActiveConnection = MM_LocalDb_STRING
Students_cmd.CommandText = "SELECT * FROM Students"
Students_cmd.Prepared = true
Students = Students_cmd.Execute
Students_numRows = 0
I have also seen various connection strings and have tried them with no success. Please help! (Thank you in advance.)
If you can, try accessing the page locally on the test server. I believe this should give you a more specific error than just the generic 500.
My thought, because this works on your dev machine, is that it's a permissions error. You should make sure that the IUSR and, I think, LOCAL SERVICE accounts have read/write permissions to the database file.