Connect to the database using what application? If you're asking how to connect an Access database front end to an Access database back end file, then you can check out the Connect property of the TableDef object.
How do I find my access database connection string?
I want to connect to my local access database in VBA. How do I find or make the details in this string that I need to do this connection?
Microsoft 365 and Office | Access | Development
4 answers
Sort by: Most helpful
-
DBG 11,531 Reputation points Volunteer Moderator2025-06-25T16:49:27.5433333+00:00 -
Dale Fye 0 Reputation points
2025-06-25T16:53:54.78+00:00 And if you don't already have that link, you can create it with the
External Data => New Data Source => From Database => Access
option on the ribbon.
-
Ken Sheridan 3,551 Reputation points2025-06-30T21:06:05.85+00:00 The following is a code snippet which creates a temporary external database and creates two tables in it, then creates links to those tables in the current database. You should be able to extract examples for necessary code for what you want to do from this:
' create temporary database in same folder as current database ' or return reference to database if already exists strTempDb = Left$(dbs.Name, Len(dbs.Name) - Len(Dir(dbs.Name))) & "BoMTemp.accdb" On Error Resume Next Set dbsTemp = CreateDatabase(strTempDb, dbLangGeneral) If Err <> 0 Then Set dbsTemp = OpenDatabase(strTempDb) End If On Error GoTo Err_Handler ' create BoM table in temporary database if doesn't exist strSQL = "CREATE TABLE BoM (MajorPartNum LONG NOT NULL, " & _ "MinorPartNum LONG NOT NULL, Quantity LONG NOT NULL, " & _ "CONSTRAINT MajorMinor PRIMARY KEY (MajorPartNum, MinorPartNum) )" On Error Resume Next dbsTemp.Execute (strSQL) On Error GoTo Err_Handler ' create BoM_Temp table in temporary database. ' note that this one has no constraint as it will be ' necessary to add duplicates of major/minor part number ' values in separate rows strSQL = "CREATE TABLE BoM_Temp (MajorPartNum LONG NOT NULL, " & _ "MinorPartNum LONG NOT NULL, Quantity LONG NOT NULL)" dbsTemp.Execute (strSQL) ' check if link to BoM_Temp table exists and if not create link On Error Resume Next Set tdf = dbs.TableDefs("BoM_Temp") If Err <> 0 Then DoCmd.TransferDatabase acLink, "Microsoft Access", strTempDb, acTable, "BoM_Temp", "BoM_Temp" Else varFld = tdf.Fields(0) If Err <> 0 Then ' refresh link if current link invalid tdf.Connect = ";DATABASE=" & strTempDb tdf.RefreshLink End If End If Err.Clear ' check if link to BoM table exists and if not create link Set tdf = dbs.TableDefs("BoM") If Err <> 0 Then DoCmd.TransferDatabase acLink, "Microsoft Access", strTempDb, acTable, "BoM", "BoM" Else varFld = tdf.Fields(0) If Err <> 0 Then ' refresh link if current link invalid tdf.Connect = ";DATABASE=" & strTempDb tdf.RefreshLink End If End If Err.ClearYou'll find the code in Bom.accdb in Bom..zip in my Dropbox public databases folder at:
-
Ken Sheridan 3,551 Reputation points2025-06-30T21:11:46.0666667+00:00 For means of browsing to and opening a file from within Access take a look at BrowseDemo.zip in the same Dropbox folder to which I gave you a link in my last reply. Oops. That was meant as a reply to another thread.