I have an access 2007 application with split database (accdb). Now I am trying to use the same application for 2 different accounts. I have already added code to relink the database. Now what I am trying to achieve in here is that it should only try to re-link dbs if the chosen account name is different from the current db. I have tried CurrentDb.Name but it returns the name of the application and not the database.
So, I have an application as A; and two databases with names as A_be and B_be. I would need code to let me know if A is currently linked to A_be or B_be.
Could someone please help with this. TIA.
On further research I figured a way out.. it may not be the best code for it but it will work. Doing a copy-paste below for reference.
Dim strFullPath As String
strFullPath = Mid(DBEngine.Workspaces(0).Databases(0).TableDefs("AnyTableName").Connect, 11)
MsgBox Dir(strFullPath)
Related
I am trying to run saved query inside VBA Access. That query is connected to another database and looks like that:
SELECT * FROM TABLE IN 'C:\USERS\Another_database.accdb'
This query is saved as "My_query" inside first Access database. VBA code looks like this:
Function My_function()
Set rst = CurrentDb.OpenRecordset("My_query", dbOpenDynaset)
End Function
When I try to run it i got an error:
Run-time error '3219'
Any ideas why? It works for normal queries (without IN 'C:\USERS\Another_database.accdb' part.
The most efficient way to get data from another Access database on an ongoing basis is with Linked Tables.
Click External Data on the ribbon, then New Data Source → From Database → Access
Browse to the source database, and make sure you choose Link to the data source by creating a linked table
Select one or more tables that you want to link
[
The linked tables will be created and you will be able to query the linked tables as if they were local to the current database.
More Information:
Office Support : Import or link to data in another Access database
Office Support: Manage Linked Tables
Maybe you need to define a Recordset first or try to remove the quotation marks you have in the example? The following example works fine:
Dim rs as Recordset
Set rs = CurrentDb.OpenRecordset("SELECT Field FROM Table IN 'here goes your path'")
Now you have an Array rs() in which you can loop.
I am very new to access and Microsoft technologies. So this might be a very silly question but I have already spent a couple of days on this issue.
I have linked a share point list with an access database and try to run an update query like below to update two date fields.
UPDATE [Table_Name]
SET [Table_Name].Start = [Table_Name].[Start]+168,
[Table_Name].[End] = [END]+168;
Every time this is giving below error,
The Microsoft Access database engine could not find the object ''. Make sure the object exists and that you spell its name and the path name correctly. If '' is not a local object, check your network connection or contact the server administrator.
I have full access on this list and able to run select queries but update queries are giving this error, I have tried to run a basic update query and that also gives the same error.
I have also tried to delete the link and create again but no luck.
Please help me to resolve this issue...any pointer is highly appreciated.
regards,
Vaibhav
I'm trying to link an ODBC database - which I have no control on - in MS Access 2007 using a Machine Data Source - I don't know if that's relevant, from what I got this means that the access is set only on this computer -.
When I follow the wizard I can select the table but when the time comes to link it I get the error message:
The database engine can't find 'WTD.DATAPOINT_5/1000'. Make sure it is a valid parameter or alias name, that it doesn't include characters or punctuation, and that the name isn't too long
I think that the problem is that one of the field is named WTD.DATAPOINT_5/1000 and that Access interprets /as a symbol of its own.
The thing is that I don't even need the data stored in this column. Right now I don't know which way to go.
Find a way to tell Access that the / is part of the field name. (Highly improbable)
Retrieve only some fields from the table using built-in Access functions.
Set the connection manually using vba and retrieving only some of the fiels. If this is the way to go I would like some pointers as I have no idea where to start.
Solution number 2: use a passthrough SQL query.
Everything is explained in this tutorial.
Solution number 3: I tried to connect directly in VBA. The code bellow works like a charm for other tables but I still get an error for the table containing the problematic field.
Dim ConnectionStr As String
ConnectionStr = "ODBC;Driver={Oracle in OraHome92};Dbq=BLA1;Uid=BLA2;Pwd=BLA3;"
DoCmd.TransferDatabase acImport, "ODBC Database", ConnectionStr, acTable, "MyTable", "NewTable"
I've inherited an Access Database that has a lot of tables, forms, and queries in it. However, I'm a PHP programmer and VBA is pretty foreign to me. I was asked to make some changes, which over the course of a few days I was able to get working (with a lot of help from old random SO posts).
After passing the database back to the users, the code that works on my computer is not working on theirs. It seems I have Access 2010 and they have 2007. As best I can tell, the function DoCmd.SetParameter doesn't exist in VBA in Access 2007.
Here's a snippet of the code :
DoCmd.SetParameter "ReportYear", Year.Value
DoCmd.SetParameter "ReportMonth", Month.Value
DoCmd.OpenQuery "doFillData"
doFillData is a query inside of Access that inserts in to another table automatically, requiring 2 parameters (year and month) before running.
The obvious answer is, make them upgrade to 2010, but I don't have that power. I assume I'll be able to create conditional code to do something different in 2007, but I can't find a similar function to use. Anyone have any ideas?
Instead of using DoCmd.OpenQuery, you want to manipulate the querydef object's named parameters and then execute it. You can use Execute options like acFailOnError when executing this way (not available with OpenQuery) and you can detect the number of records affected.
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("doFillData")
qdf.Parameter("ReportYear") = Year.Value
qdf.Parameter("ReportMonth") = Month.Value
qdf.Execute
MsgBox qdf.RecordsAffected & " records were affected."
I currently have a data source of a large table, sitting in workbook1. From workbook2, which is currently empty, I wish to set up a DSN connection to workbook1, so that I can query it from workbook 2.
In the SQL query result, I wish to display extra columns which are calculated using User-Defined VBA functions, the arguments of which will be other fields from the data source.
Example:
Workbook1 is Field1, F2, F3 and F4. I wish to query this and display all records, but additionally I wish to have F5=UDF(F3,F4).
I have been advised already that the solution to this is:
SELECT UDF(F3,F4) as F5
FROM \SourceWorkBookLocation\SourceWorkBook
IN ACCESS:
The problem I am having in access is not at the top of my list right now, relates to data types and trying to determine if a number in a string is <25. But the main problem is in MS Query:
IN EXCEL/MS QUERY:
The function is just not recognized; "undefined function"
I am not sure how to get it to see the function? My end goal here is to build a front end in excel, and have vba querying appropriately using user input variables passed to the queries. The querying will be done on a separately updated workbook.
Any ideas on how to get MS Query to see my UDF and accept what I am doing? Could it be a driver issue? There are a range of excel drivers to choose from.
Thanks
Looking at the info you have provided, you have tried to use two Excel workbooks as tables to query using Excel VBA UDF. Now I assume you are going to use these workbooks as your tables but in MS Access.
All most all databases is able to read standard SQL. See the thing is that each database is able to handle functions writting in their own space. In your case please write your UDF in Access VBA. Then try to execute to the same.
This is a common issue sometimes people do face, either tyring to access MS Access UDFs from Excel or vise versa. In a nutshell, when you're running MS Access, queries can call back into VBA. But when you're going through ODBC or ADO, the JET engine doesn't have the whole VBA model to draw on because it's simply not running.
You could try to do something like this:
Dim objExcl As Object
Set objExcl = CreateObject("Excel.Application")
objExcl.OpenCurrentDatabase "ExcelFileName/Path"
objExcl.Run ("UDFName")
objExcl.CloseCurrentDatabase
Set objExcl = Nothing
Frankly I prefer moving the UDF in to Acces..
References:
Create Access UDF
http://www.sqlexamples.info/SQL/inlineudf.htm